Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Date Format

$
0
0

Hi,

The code below that I run where I am trying to format a [DATE] variable, I get this error message:

Msg 8116, Level 16, State 1, Line 17
Argument data type nvarchar is invalid for argument 1 of format function.

Any idea how I would resolve this please? 


SELECT 
Country as Country,
format ([DATE], 'yyyyMM') as Date_In,
format ([DATE], 'yyyy') as Date_InYear,
Business_type,
sum([Value]) as Total_Amount

FROM AJX_Q

UNPIVOT ([Value] for [Date] IN 
(
[JAN17],
[FEB17],
[MAR17],
[APR17],
[MAY17],
[JUN17],
[JUL17],
[AUG17],
[SEP17],
[OCT17],
[NOV17],
[DEC17],
[JAN18],
[FEB18],
[MAR18],
[APR18],
[MAY18],
[JUN18],
[JUL18],
[AUG18],
[SEP18],
[OCT18],
[NOV18],
[DEC18],
[JAN19],
[FEB19],
[MAR19],
[APR19],
[MAY19],
[JUN19],
[JUL19],
[AUG19],
[SEP19],
[OCT19],
[NOV19],
[DEC19])) as UnpivotTable

group by 
format ([DATE], 'yyyyMM'),
format ([DATE], 'yyyy') ,
Country,
Business_type



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>