套管月份名称作为列名称 [英] Casing Month Names as column names

查看:85
本文介绍了套管月份名称作为列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

Hi I have the following code:

SELECT
    #A.strClientCode,
    'TotalCurr' = SUM(#A.TotalCurr),
    'Total1' = SUM(#A.Total1),
    'Total2' = SUM(#A.Total2),
    'Total3' = SUM(#A.Total3)
INTO
    #PIVOT




具有总计"值的列名称应分别是当前日期的月份名称.我需要将字段中的总计"替换为日期和前几个月的名称.

例如. TotalCurr必须是12月
ToTal1必须是11月
\\\\\\
等等...
有没有一种方法可以获取日期并将月份名称设置为这些列?


Maby




the Column names with the "Total" values,should be month names respectively to the current date. I need to replace the fields with "Total" in them,to the dates and previous months names.

eg. TotalCurr needs to be December
ToTal1 needs to be November
\\\\\\
and so on...
is there a way of just getting the date and setting the month name to those column?


Maby

declare @Date as date
Set @Date = GETDATE()




然后----"month(@date)=#A.TotalCurr"




and then ---- "month(@date) = #A.TotalCurr"

something in that line.

推荐答案

尝试:

Try:

declare @sql nvarchar(100)
Set @sql = 'select  GETDATE() as ' + DATENAME(month, getdate())
exec sp_executesql @sql


这篇关于套管月份名称作为列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆