question

ChristopherJack-1763 avatar image
0 Votes"
ChristopherJack-1763 asked JingyangLi answered

Invalid column name

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?





sql-server-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JingyangLi avatar image
1 Vote"
JingyangLi answered

Print our your sql string.
My guess is this:
and sales_division = ''' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)+''''

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ChristopherJack-1763 avatar image
0 Votes"
ChristopherJack-1763 answered

Found the answer .. needed to add a few more quoates

 sales_division = ''' + (SELECT schema_name FROM #schema WHERE ROWNUMBER = @Init)+''''
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.