使用Select语句的列名 [英] To work with Column Names of a Select Statement
本文介绍了使用Select语句的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Friends
我现在面临一个问题,因为我想将变量的值赋予要在选择语句中选择的列名".
像
如果我有一个变量@date =''01-2012''
那么我想将此值作为我的select语句的标题
就像
选择a,b,c,
d AS @date
从表
所以我需要的是我希望@date值作为select语句的标题.
在此先谢谢您.
Hi Friends
I am facing one problem right now as " I want to give the value of a variable to the column name that i am going to select in a select statement ".
Examplly like
if i have a variable @date=''01-2012''
then i want this value as a heading to my select statement
which is like
SELECT a , b ,c,
d AS @date
from table
So what i need is that i want @date Value to come as the heading of the select statement.
Thanks in advance .
推荐答案
您可以直接将常量代替变量:
Instead of variable you can directly put the constant:
SELECT a , b ,c, d AS '01-2012' from table_name
或您需要执行动态查询:
or you need to execute the dynamic query:
declare @tdate varchar(20)
set @tdate = '01-2011'
exec('select sellerid, sellername as [' + @tdate + '] from sellers')
这篇关于使用Select语句的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文