Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have the following code
SET @sqlCommand = '
select
*
from
#temptable
where
SALES_OFFICE not in
(SELECT [SalesOfficeCode] from ' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)
+ '.[DimSalesOffice]) and sales_division = ' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)
However I am receiving the error
Invalid column name
The error seems to be related to the last part when is doing the comparison
sales_division = ' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)
The part above that pulls the row value fine? Any ideas?
Print our your sql string.
My guess is this:
and sales_division = ''' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)+''''
Found the answer .. needed to add a few more quoates
sales_division = ''' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)+''''