kowsika devi
asked on
convert month name to month number in sql server 2012
convert month name to month number in sql server 2012
Eg : Aug means current yearand month (201708)
Eg : Aug means current yearand month (201708)
Where did you store the month names?
ASKER
its in my table already i saved i need to change aug as 201708 formats
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Vitor Montalvão :-)
another way to do that
declare @yourTable table
(
YourMonthName varchar(3)
)
insert into @yourTable
values
('Jan'),
('Feb'),
('Mar'),
('Apr'),
('May'),
('Jun'),
('Jul'),
('Aug'),
('Sep'),
('Oct'),
('Nov'),
('Dec')
select Convert(varchar(6), CAST(CONCAT('1', YourMonthName, Year(getdate())) as datetime ), 112) YearMonth
from @yourTable
one more :)
declare @yourTable table
(
YourMonthName varchar(3)
)
insert into @yourTable
values
('Jan'),
('Feb'),
('Mar'),
('Apr'),
('May'),
('Jun'),
('Jul'),
('Aug'),
('Sep'),
('Oct'),
('Nov'),
('Dec')
Declare @sYear varchar (4)='2017'
select YourMonthName,CONVERT(varchar(6), convert(DATETIME,YourMonthName+' 1 '+@sYear+' 12:00AM'),112)
from @yourTable
yet another one
declare @mon as varchar(3)='Aug';
select 1+CharIndex(@mon,'JanFebMarAprMayJunJlyAugSepOctNovDec')/3
8
ID: 42253666 : proposed solution is not the only one...
and being the first is not enough to get whole share :)
also, it always return 2017XX...
ID: 42253776
ID: 42254508
ID: 42254672
all provide some solution to the question, and points should be shared...
and being the first is not enough to get whole share :)
also, it always return 2017XX...
ID: 42253776
ID: 42254508
ID: 42254672
all provide some solution to the question, and points should be shared...