A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Michael M.M. D'Angelo
Check this query:
SELECT RIGHT(Column_Nmae,2)+' - '+ CONVERT(VARCHAR,StartDate,103) +' - '+CONVERT(VARCHAR,DATEADD(DAY,-1,DATEADD(MONTH,1,StartDate)),103)+' '+DATENAME(MM,StartDate) AS [Month]
FROM LedgerParameters
UNPIVOT(StartDate FOR Column_Nmae IN([PerStartThis01], [PerStartThis02], [PerStartThis03], [PerStartThis04], [PerStartThis05], [PerStartThis06],
[PerStartThis07], [PerStartThis08], [PerStartThis09], [PerStartThis10], [PerStartThis11], [PerStartThis12]))U
If you don't want to use UNPIVOT keyword,you could also try Cross Apply like this:
SELECT RIGHT(Column_Name,2)+' - '+ CONVERT(VARCHAR,StartDate,103) +' - '+CONVERT(VARCHAR,DATEADD(DAY,-1,DATEADD(MONTH,1,StartDate)),103)+' '+DATENAME(MM,StartDate) AS [Month]
FROM #LedgerParameters CROSS APPLY(VALUES([PerStartThis01],'PerStartThis01'), ([PerStartThis02],'PerStartThis02'), ([PerStartThis03],'PerStartThis03'),
([PerStartThis04],'PerStartThis04'), ([PerStartThis05],'PerStartThis05'), ([PerStartThis06],'PerStartThis06'),
([PerStartThis07],'PerStartThis07'), ([PerStartThis08],'PerStartThis08'), ([PerStartThis09],'PerStartThis09'),
([PerStartThis10],'PerStartThis10'), ([PerStartThis11],'PerStartThis11'), ([PerStartThis12],'PerStartThis12'))C(StartDate,Column_Name)
Output: