Link to home
Start Free TrialLog in
Avatar of mburk1968
mburk1968Flag for United States of America

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

Open in new window

Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

Try

SELECT DISTINCT [filedate], CONVERT(CHAR(3), DATENAME(MONTH, [filedate]) + ' ' + YEAR([filedate]) as DisplayDate
FROM [dbo].[NC_ProviderInfo]
ORDER BY [filedate] DESC

Kelvin
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

Open in new window

Avatar of mburk1968

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
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial