Hi
Please help me
I want to get this output
OUTPUT:-
MonthName Month
---------------
Nov 11
Dec 12
Jan 1
My table structure like and data this
Month ( int)
11
11
11
12
12
12
1
1
1
my query is this please help me regarding this
SELECT DISTINCT CASE [Month] WHEN 6 THEN 'Jun'
WHEN 7 THEN 'Jul' WHEN 8 THEN 'Aug' WHEN 9 THEN 'Sep'
WHEN 10 THEN 'Oct' WHEN 11 THEN 'Nov' WHEN 12 THEN 'Dec'
WHEN 1 THEN 'Jan' WHEN 2 THEN 'Feb' WHEN 3 THEN 'Mar' WHEN 4 THEN 'Apr'
ELSE 'May' END AS MonthName,[Month] FROM TESTTable
order by month
Please give me answer or suggestion.
Thanks In Advance,
Jitendra Patel
Loading
Jitendra PatelPosted Mar 8, 2010, 8:04 AM
Thanks a lot for help me,
I have solved my problem using in stored procedure #Temporary table.
There are no any way to get my Output,
Thanks,
Jitendra Patel
Jitendra PatelPosted Mar 8, 2010, 6:44 AM
Above query out put is not set to my requirement,
My out put is this........
my table data like this
Month
11
12
5
6
3
4
2
5
3
8
6
My output like this
my first month start with "JUNE" not "January"
Jun
July
Aug
Sep
Oct
.
.
.
.
May
My first month JUNE and Last Month is May
Thanks,
Jitendra
Hirendra SisodiyaPosted Mar 8, 2010, 5:44 AM
Rahul RayPosted Mar 8, 2010, 5:34 AM
Please check the below query
--CREATE TABLE #TABL(
--MONTH INT
--)
--INSERT INTO #TABL VALUES(11)
--INSERT INTO #TABL VALUES(11)
--INSERT INTO #TABL VALUES(12)
--INSERT INTO #TABL VALUES(12)
--INSERT INTO #TABL VALUES(12)
--INSERT INTO #TABL VALUES(1)
--INSERT INTO #TABL VALUES(1)
--INSERT INTO #TABL VALUES(1)
SELECT DISTINCT
CASE
WHEN MONTH=1 THEN 'JAN'
WHEN MONTH=2 THEN 'FEB'
WHEN MONTH=3 THEN 'MAR'
WHEN MONTH=4 THEN 'APR'
WHEN MONTH=5 THEN 'MAY'
WHEN MONTH=6 THEN 'JUN'
WHEN MONTH=7 THEN 'JULY'
WHEN MONTH=8 THEN 'AUG'
WHEN MONTH=9 THEN 'SEP'
WHEN MONTH=10 THEN 'OCT'
WHEN MONTH=11 THEN 'NOV'
WHEN MONTH=12 THEN 'DEC'
END AS "MONTHNAME",
CASE
WHEN MONTH=1 THEN 1
WHEN MONTH=2 THEN 2
WHEN MONTH=3 THEN 3
WHEN MONTH=4 THEN 4
WHEN MONTH=5 THEN 5
WHEN MONTH=6 THEN 6
WHEN MONTH=7 THEN 7
WHEN MONTH=8 THEN 8
WHEN MONTH=9 THEN 9
WHEN MONTH=10 THEN 10
WHEN MONTH=11 THEN 11
WHEN MONTH=12 THEN 12
END AS "MONTH" FROM #TABL ORDER BY MONTH ASC
Out Put:
MONTHNAME MONTH
--------- -----------
JAN 1
NOV 11
DEC 12
If the above quary is not fit for ur senario pls inform me and
send requirement in briefly
Thanks & Regards
Rahul Deb Ray
Jitendra PatelPosted Mar 8, 2010, 1:36 AM
My Year is start with Jun-2009 to May-2010.
My output is
Jun-2009 | Jul-2009 | aug-2009 |..................| mar-2010 | apr-2010 | may-2010
this query is not usefull to me.
Thanks,
Jitendra Patel
Hirendra SisodiyaPosted Mar 6, 2010, 7:20 AM
select Distinct [Month] as [month],
CASE [Month]
when '1' then 'jun'
when '2' then 'Feb'
when '3' then 'Mar'
when '4' then 'Apr'
when '5' then 'May'
when '6' then 'jun'
when '7' then 'July'
when '8' then 'Auj'
when '9' then 'Sep'
when '10' then 'Oct'
when '11' then 'Nov'
when '12' then 'Dec'
END as [monthname]
from TESTTable
thank you
check answere, if you like this