mburk1968
asked on
query Syntax
I have the following query that pulls distinct filedate from my table. I need to add a column DisplayDate to use in a dropdown so an example would be 1016-09-01 and in my matching column I want Sep 2016
SELECT DISTINCT [filedate]
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC
Try below, Format Function , Works with SQL 2012 & above !!
SELECT DISTINCT [filedate] , FORMAT([filedate], 'MMMM yyyy') DisplayDate
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC
ASKER
receiving the following
Msg 245, Level 16, State 1, Procedure dbo.qry_ActiveMonths, Line 15 [Batch Start Line 0]
Conversion failed when converting the nvarchar value 'July ' to data type int.
SELECT DISTINCT [filedate], CONVERT(CHAR(3), DATENAME(MONTH, [filedate]) + ' ' + YEAR([filedate]) as DisplayDate
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC
Msg 245, Level 16, State 1, Procedure dbo.qry_ActiveMonths, Line 15 [Batch Start Line 0]
Conversion failed when converting the nvarchar value 'July ' to data type int.
SELECT DISTINCT [filedate], CONVERT(CHAR(3), DATENAME(MONTH, [filedate]) + ' ' + YEAR([filedate]) as DisplayDate
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT DISTINCT [filedate], CONVERT(CHAR(3), DATENAME(MONTH, [filedate]) + ' ' + YEAR([filedate]) as DisplayDate
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC
Kelvin