Friday, January 28, 2011

Dynamic Sql-srever - table column header name

Dynamic Sql-srever - table column header name
 
declare @colnm varchar(20)
declare @strsql varchar(2000)
set @colnm='1625195'
--set @strsql='select ['+  @colnm + '] from ia_book1 where ['+  @colnm + '] =''1625195'+''+char(39)
set @strsql='select * from ia_book1 where ['+  @colnm + '] ='+char(39)+@colnm +char(39)
Print @strsql
exec(@strsql)

No comments: