June 13, 2007 at 1:31 pm
I have the following two queries in a stored procedure. The second query is attempting a table join using the "join_cust" column from the "#Cust" temporary table created in the first query. The first query works, but as you can see from the error message I'm getting at the bottom, SQL doesn't like the "join_cust" column in the second query.
Can anyone help me with resolving this error?
Thanks!
(Using SQL Server 2005)
Select Cust_Name1, 'US' + cust_no_text As join_cust
Into #Cust
From eRapid.cse.dbo.cs_customers
Where country_code = 'US'
Order By 'US' + cust_no_text
Select Case When Right(doc_number,2) <> '00' Then 'Nope'
Else doc_number
End As order_no
Into #QuotesTemp1
From (eRapid.cse.dbo.doc_header h Inner Join
eRapid.cse.dbo.cs_project p On h.doc_number = p.Order_no)
Left Join #Cust c On p.Cust_name = c.join_cust
Msg 207, Level 16, State 1, Procedure RunUpdateConfig, Line 17
Invalid column name 'join_cust'.
June 13, 2007 at 2:25 pm
Step one - refacture names (doc_number =order_no??)
Step two - make the first temp table a derived table
Select Case When Right(doc_number,2) '00' Then 'Nope'
Else doc_number End As order_no
Into #QuotesTemp1
From eRapid.cse.dbo.doc_header h
Inner Join eRapid.cse.dbo.cs_project p On h.doc_number = p.Order_no
Left Join
(Select Cust_Name1, 'US' + cust_no_text join_cust
From eRapid.cse.dbo.cs_customers
Where country_code = 'US'
) c On p.Cust_name = c.join_cust
The SQL above did not correct 'invalid column name' however it may point out where in your code the error is occuring.
The derived table may have a nice RTI if all your query is running against a linked server.
Good Luck
June 13, 2007 at 2:44 pm
Thanks Daryl.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply