Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

What is wrong with this Dynamic Sql Query?

$
0
0

A stored procedure using following dynamic sql 

--declare @Dictionaryvarchar(128) = 'Test'
 --declare @Stringvarchar(1000)='Test1'
 
select @String = "select 202,'" + @Dictionary + "','Value',
DictionaryIndex, Value,SeqNo
from " + @Dictionary + " 
order by SeqNo"

--print (@String)

When i drop and recreate stored procedure it creates it successfully. But i if try to print the script above it gives error 

Msg 207, Level 16, State 1, Line 5
Invalid column name 'select 202,''.
Msg 207, Level 16, State 1, Line 5
Invalid column name '','Value',
DictionaryIndex, Value,SeqNo
from '.
Msg 207, Level 16, State 1, Line 7
Invalid column name ' 
order by SeqNo'.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>