Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all,I need to know a solution for the following: declare @r1 as varchar (5) set @r1='Title' select name as @r1 from customeri need the column records from the customer table with the header 'Title'ex: Title samp1 samp2
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-11-28 : 03:42:50
this is a display issue and should be handled at front end. Why do you have to change sql query for this?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-11-28 : 03:45:20
if you want to do it in sql, you need to use dynamic sql
declare @r1 as varchar (5),@sql nvarchar(1000),@params nvarchar(500)set @r1='Title'set @params ='@r varchar(5)'set @sql = 'select name as ' + @r1 + ' from customer'EXEC sp_executesql @sql,@params,@r1
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
quote:Originally posted by sindhu sarah Hi all,I need to know a solution for the following: declare @r1 as varchar (5) set @r1='Title' select name as @r1 from customeri need the column records from the customer table with the header 'Title'ex: Title samp1 samp2
What did you change after one year of asking this question?MadhivananFailing to plan is Planning to fail