Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case or other....

Author  Topic 

santana
Yak Posting Veteran

72 Posts

Posted - 2010-02-24 : 08:49:12
Hi,

I have this query below. But I need to inlcude Dec - decembre, but CASE is only for 10 levels. How can I include Dec? How can I do this?

CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 1 then ('Jan') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 2 then ('Feb') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 3 then ('Mar') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 4 then ('Apr') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 5 then ('May') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 6 then ('Jun') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 7 then ('Jul') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 8 then ('Aug') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 9 then ('Sep') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 10 then ('Oct') else
('Nov')
end end end end end end end end end end

Thanks.

Regards,

santana

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-24 : 08:51:13
You can simply do

select left(datename(month,quality.dbo.tb_inquiries.date),3) from your_table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-02-24 : 08:54:52
You can use

SELECT SUBSTRING(DATENAME(MONTH, DATEPART(M, GETDATE())), 1, 3)

Replace Getdate() with your 'quality.dbo.tb_inquiries.date'

Vabhav T
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-02-24 : 08:55:54
Madhi's query is more efficient you can refer it.

Vabhav T
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-02-24 : 09:11:13
quote:
Originally posted by santana

Hi,

I have this query below. But I need to inlcude Dec - decembre, but CASE is only for 10 levels. How can I include Dec? How can I do this?

CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 1 then ('Jan') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 2 then ('Feb') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 3 then ('Mar') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 4 then ('Apr') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 5 then ('May') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 6 then ('Jun') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 7 then ('Jul') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 8 then ('Aug') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 9 then ('Sep') else
CASE WHEN DATEPART(month, quality.dbo.tb_inquiries.date) = 10 then ('Oct') else
('Nov')
end end end end end end end end end end

Thanks.

Regards,

santana



Also remember to use syntax for Case expressions for scenarios like above this way
CASE expression
WHEN expression1 THEN expression1
WHEN expression2 THEN expression2] [...]]
END



PBUH
Go to Top of Page

santana
Yak Posting Veteran

72 Posts

Posted - 2010-02-24 : 09:46:31
Thanks for all replays.

I used that: select left(datename(month,quality.dbo.tb_inquiries.date),3) from your_table

At it is working perfectly!

Regards,
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-24 : 09:47:14
quote:
Originally posted by santana

Thanks for all replays.

I used that: select left(datename(month,quality.dbo.tb_inquiries.date),3) from your_table

At it is working perfectly!

Regards,



You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -