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
 CAST

Author  Topic 

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-12-14 : 06:09:58
I have
[CODE]
CASE
WHEN (a.type_id in (9))
THEN a.duration
ELSE 0 --CAST ( expression AS data_type )
END 'Time'
[/CODE]

I need the duration to be displayed if type is 9 only.
so otherwise id ideally want 'N/A' displayed..
but it won't display it as its not an int ..

is there a way i can just display it temporarily
instaed of 0 ?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-14 : 06:13:57
[code]CASE
WHEN (a.type_id in (9))
THEN cast(a.duration as varchar(10))
ELSE 'N/A'
END 'Time'[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-12-14 : 06:14:44
PS
[CODE]
ELSE (CAST (a.duration as varchar(10)) AND 'N-A')
[/CODE]
doesn't work either...
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-12-14 : 06:15:49
CASE
WHEN (a.type_id in (9))
THEN cast(a.duration as varchar(10))
ELSE 'N/A'
END 'Time'

im not sure this will work as i need to display the duration in this case ..
ie the int ..
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2007-12-14 : 06:21:28
sorry it does work ..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-14 : 06:26:25
quote:
Originally posted by pazzy11

CASE
WHEN (a.type_id in (9))
THEN cast(a.duration as varchar(10))
ELSE 'N/A'
END 'Time'

im not sure this will work as i need to display the duration in this case ..
ie the int ..



Always use alias name preceded by AS and dont use single quotes
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/14/should-alias-names-be-preceded-by-as.aspx


Madhivanan

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

- Advertisement -