SQL:如何使用参数变量重命名标题?

问题描述 投票:0回答:0

如何将列'Q1_2022 的标题重命名为参数@filteredDate。下面是工作查询,但不知道如何使用@filteredDate 重命名标头“03-31-2022”。请建议。

declare @filteredDate Date = '03-31-2022'

select *
from
(SELECT 'BSA' as tabs, ' xyz' as Type, ColumnName AS 'Report',
  ColumnValue AS 'Q1_2022'
FROM
(
  SELECT
SUM(CAST(col1 AS BIGINT)) AS col1_,
SUM(CAST(col2 AS BIGINT)) AS col2_
FROM [dbo].[table1] table1
FULL OUTER JOIN [dbo].[table2] table2 ON table1.ID = table2.ID
WHERE table5.Institution = '100_bank'
and FileDate = @filteredDate
) p
 UNPIVOT
(
  ColumnValue FOR ColumnName IN (col1_ , col2_)) unpiv);
sql sql-server parameters declare
© www.soinside.com 2019 - 2024. All rights reserved.