Hi,
I have a simple query that getting some datas like below;
ID , Month
1 5
2 12
3 3
For example I want to change "Month" column's value. For example if there is 1, and I'll show with January. And if there is 12, I'll show December.
How can I do that with MSSQL?
Regards.
Loading
Pradeep ShetPosted Jan 14, 2015, 11:51 AM
Find the query below
SELECT ID, MONTHNAME('2001-' + Month + '-01') AS mnth
FROM table
Hope this answers your question.
Manish Kumar ChoudharyPosted Jan 7, 2015, 11:09 PM
if you want to pass only month number then you can do something like
DECLARE @Mth smallint
SET @Mth = 1
SELECT DateName(mm,DATEADD(mm,@Mth,-1)) as [MonthName]
if you want to apply it for your table then use it likeCreate Table #Monthtbl
(
Id int,
MonthNo int
)
insert into #Monthtbl values(1,1)
insert into #Monthtbl values(2,2)
insert into #Monthtbl values(3,3)
insert into #Monthtbl values(4,4)
SELECT Id,DateName(mm,DATEADD(mm,MonthNo,-1)) as [MonthName] from #Monthtbl
VulpesPosted Jan 7, 2015, 6:18 PM