Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

below is my query to return the month name from month number

SQL
SELECT DATENAME(MONTH, CAST(CAST(YEAR(GETDATE()) AS VARCHAR) 
+ '-' + CAST('2' AS VARCHAR) + '-01' AS DATETIME)) AS MonthName


it shows output as February.
but i want only first 3 letters only in the same query.

Thank you
Posted

1 solution

Hello ,

you have to use
SQL
SUBSTRING 
in your query to get first 3 letters of the month.

modify the query
SQL
SELECT SUBSTRING(DATENAME(MONTH, CAST(CAST(YEAR(GETDATE()) AS VARCHAR)
+ '-' + CAST('2' AS VARCHAR) + '-01' AS DATETIME)),1,3) AS MonthName


For more details on substring go through This link

thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900