如何在SQL中将字符串附加到表列名 [英] How to append string to table column name in SQL
本文介绍了如何在SQL中将字符串附加到表列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我想在从表中选择数据时将日期连接到列名。
例如:
Hello,
I want to concatenate the date to the column name while selecting the data from a table.
E.g.:
SELECT field1 as newfieldname --for changing the field1 to newfieldname
FROM tablename
我想要一个具有当前日期时间的新字段名称,所以它应该像这样newfieldname_10 / 08 / 2013。我们如何在SQL select语句中将日期时间附加到列名?
谢谢,
Ginnas
I want a new field name with current datetime, so it should be like this newfieldname_10/08/2013. How can we append a datetime to the column name in a SQL select statement?
Thanks,
Ginnas
推荐答案
如果你的意思是你想要字符串fieldname那么就这样做。
If you mean you want the string "fieldname" then do this.
SELECT 'fieldname_' + CONVERT(NVARCHAR (50), GetDate())
如果你的意思是你想要从该字段名称中取出该值然后执行
If you actually mean you want the value out of that field name then do
SELECT fieldName + CONVERT(NVARCHAR (50), GetDate())
FROM table1 ...
这篇关于如何在SQL中将字符串附加到表列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文