sql server - How can I use SQL to get a variable value from a literal? -


part 1

declare @a int declare @b nvarchar(20)  set @a=123 set @b='@a' 

part 2

declare @sql nvarchar(max) set @sql='select ' + @b  exec sp_executesql @sql --should return 123 

directly referencing @a in non-dynamic sql not acceptable task.

the above in part 2 generically trying do. understand variable out of scope , won't work done above. how use @b value of @a?

i didn't understand whole thing asking, can define variables on sp_executesql:

exec sp_executesql @sql, n'@a int', @a = @a 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -