2013-03-22 25 views
1

我在报告中有一个特定的场景,我想要获取特定格式的月份。Sybase查询:如何从日期获取月份

Input : 
Month : 2 Digit OR 1 Digit OR 0 

Expectation: 
If I pass 2 Digit : e.g. 10 o/p should be 10 
If I pass 1 Digit : e.g. 1 o/p should be 01 
If I pass 0  : e.g. 0 o/p should be blank 

but I need help to when I pass 0 and I get Blank. 

Please Help/Advice 
AT 
+0

请问你查询什么样子的? – 2013-03-22 16:40:20

+0

select isnull(rtrim(right('0'+ isnull(convert(varchar(2),'12'),isnull('12','')),2)),null) – user2199973 2013-03-22 17:23:00

回答

0

我认为这会为你工作:

SELECT CASE 
     WHEN @month = 0 THEN '' 
     ELSE RIGHT ('0' + @month, 2) 
     END AS Month 
相关问题