SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Parameter as a header in select statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sindhu sarah
Starting Member

United Arab Emirates
34 Posts

Posted - 11/28/2011 :  03:41:24  Show Profile  Reply with Quote
Hi all,

I need to know a solution for the following:

declare @r1 as varchar (5)
set @r1='Title'
select name as @r1 from customer

i need the column records from the customer table with the header 'Title'

ex: Title
samp1
samp2


Edited by - sindhu sarah on 12/27/2012 00:18:07

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/28/2011 :  03:42:50  Show Profile  Reply with Quote
this is a display issue and should be handled at front end. Why do you have to change sql query for this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/28/2011 :  03:45:20  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 11/28/2011 :  07:21:54  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=168430

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 12/27/2012 :  08:09:51  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 customer

i 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?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000