SQL DATENAME() QUESTION...
-
I have a number representing a month: DECLARE @MONTH INT SET @MONTH = 5 How can I use the DATENAME() function to get the name of the month? I must have a full date variable to use this and I don't know how to build a date using @MONTH as its month... PLEASE HELP...
-
I have a number representing a month: DECLARE @MONTH INT SET @MONTH = 5 How can I use the DATENAME() function to get the name of the month? I must have a full date variable to use this and I don't know how to build a date using @MONTH as its month... PLEASE HELP...
lior654#hotmail.com wrote:
How can I use the DATENAME() function to get the name of the month?
DATENAME() can accept a varchar as the date, so you can just create a random date, with the month as you want:
DECLARE @somedate varchar(20);
SET @somedate = '2005-01-01';
SELECT datename(month,@somedate);This will return "January". However, I would recommend that user interface type things like getting a month name are best carried out in the UI layer leaving the data layer to get on with things that it is good at (like manipulating the data in the database)
My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius