Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:38:25+00:00 2026-06-13T11:38:25+00:00

All… based on another question I’ve posted here recently, I built this stored procedure,

  • 0

All… based on another question I’ve posted here recently, I built this stored procedure, but when executed, I receive the error in the title.

As you can see, I tried to remove any aliases, but it didn’t matter. Not sure how to use PRINT to see the issue on this either. Of course the isolated SELECT statement works on its own.

I can even pull results from my temp table after the error appears. So is it a problem in this script or the results? Appreciate your assistance. I also only used the WHERE statement to limit the test results.

    ALTER PROC ap_vhdr_test AS
SET NOCOUNT ON
IF OBJECT_ID('temp.dbo.#ap_vend_det') is NOT NULL
DROP TABLE #ap_vend_det;

CREATE TABLE #ap_vend_det           
(db_name varchar(32)
, vendor_name varchar(40)
, vendor_code varchar(12)
, voucher_no varchar(16)
, invoice_num varchar(16)
, inv_date varchar(16)
, due_date varchar(16)
, apply_date varchar(16)
, total float
, line_desc varchar(40)
, company_id smallint
, gl_num varchar(32)
, acct_site varchar(32)
, sort_code varchar(32)
, nat_gl varchar(32)
, gl_desc varchar(40)
, category nvarchar(510)
, sub_category nvarchar(510)
, po_num varchar(16)
, vendor_class varchar(8)
)
INSERT INTO #ap_vend_det
EXEC sp_MSforeachdb N'IF ''?'' NOT IN ( ''model'',''tempdb'',''master'',''msdb'')
BEGIN SELECT DISTINCT db_name = ''?''
, amaster.addr1 --as vendor_name
, amaster.vendor_code --as vendor_code
, apdet.trx_ctrl_num --as voucher_no
, aphdr.doc_ctrl_num --as invoice_num
, CONVERT(varchar(16),dateadd(dd,(aphdr.date_doc - 639906),''1/1/1753''),101) --as inv_date 
, CONVERT(varchar(16),dateadd(dd,(aphdr.date_due - 639906),''1/1/1753''),101) --as due_date
, CONVERT(varchar(16),dateadd(dd,(aphdr.date_applied - 639906),''1/1/1753''),101) --as apply_date
, aphdr.amt_net --as total
, aphdr.doc_desc --as line_desc
, gldet.company_id --as company_id
, gldet.account_code --as gl_num
, gldet.seg2_code --as acct_site
, gldet.seg3_code --as sort_code
, gldet.seg1_code --as nat_gl
, gldet.description --as gl_desc
, ap_coa.group_header --as category
, ap_coa.group_label  --as sub_category
, apdet.po_ctrl_num --as po_num
, apvend.vend_class_code --as vendor_class
FROM ?.dbo.amaster --amaster
JOIN ?.dbo.aphdr --aphdr                        --**
    ON amaster.vendor_code = aphdr.vendor_code
    AND amaster.pay_to_code = aphdr.pay_to_code
JOIN ?.dbo.apdet --apdet
    ON aphdr.trx_ctrl_num = apdet.trx_ctrl_num
JOIN ?.dbo.gldet --gldet
    ON aphdr.journal_ctrl_num = gldet.journal_ctrl_num
JOIN ?.dbo.glt --glt
    ON gldet.journal_ctrl_num = glt.journal_ctrl_num
JOIN ?.dbo.apvend --apvend
    ON amaster.vendor_code = apvend.vendor_code
JOIN reps.dbo.ap_coa --ap_coa
    ON gldet.seg1_code = ap_coa.acct_code
WHERE aphdr.date_applied >= ''734785''              
END';

SELECT * FROM #ap_vend_det;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:38:26+00:00Added an answer on June 13, 2026 at 11:38 am

    This will fail if you have database names that have spaces or other characters in them. You need to enclose them in square brackets, e.g.

    FROM [?].dbo.amaster --amaster
    

    Not only that, because you are using 3 part names, you also need to alias the tables in the FROM clause.

    FROM [?].dbo.amaster amaster
    JOIN [?].dbo.aphdr aphdr                        --**
        ON amaster.vendor_code = aphdr.vendor_code
        AND amaster.pay_to_code = aphdr.pay_to_code
    JOIN [?].dbo.apdet apdet
        ON aphdr.trx_ctrl_num = apdet.trx_ctrl_num
    JOIN [?].dbo.gldet gldet
        ON aphdr.journal_ctrl_num = gldet.journal_ctrl_num
    JOIN [?].dbo.glt glt
        ON gldet.journal_ctrl_num = glt.journal_ctrl_num
    JOIN [?].dbo.apvend apvend
        ON amaster.vendor_code = apvend.vendor_code
    JOIN reps.dbo.ap_coa ap_coa
        ON gldet.seg1_code = ap_coa.acct_code
    WHERE aphdr.date_applied >= ''734785''     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All is in the question i have tried this : $('#my-div').css('box-shadow'); but it returns
All, This is a follow up for my question here . My setup: Visual
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
all.I'm a beginner of Mysql and I have one simple question here. I want
All this might look too trivial but read it through - I have simple
all. We're trying to get some intersect collisions working, but the problem experience is
All my code is here,quite simple,and I don't konw where it goes wrong. Person
All the guys probably will recommend that I read the follow previously question in
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
All, I am trying to create a table to receive user inputs (UGC). This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.