Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cast() within isnull or outside?
Message
From
14/09/2007 12:47:52
 
 
To
14/09/2007 12:37:11
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01254374
Message ID:
01254378
Views:
25
This message has been marked as a message which has helped to the initial question of the thread.
>Hi All,
>
>I have a select statement (huge) and I need to change data type DT to basically time, but since SQL Server does not do time, to a character string. I was thinking that I could just do a cast() on it, but since I already have an ISnull() around it, I am not sure where to put the cast() or convert().
>
>
>  isnull(tab1.RunSrv_TimeAtSrv,'') AS AM_RunSrv_TimeAtSrv,
>
>
>so maybe:
>
>  isnull(convert(char(8),tab1.RunSrv_TimeAtSrv, 108),'') AS AM_RunSrv_TimeAtSrv,
>
>
>this gettes me hh:mm:ss, what I need is hh:mm AM/PM
>
>Anyone know how I can get that?
>
>TIA
>Beth
DECLARE @Test DATETIME
SET @Test = GETDATE()
SELECT ISNULL(SUBSTRING(CONVERT(char(27), @test, 100),14,6),'')
ISNULL must be the first function. Try this to see what happens:
DECLARE @Test DATETIME
--SET @Test = GETDATE()
SELECT ISNULL(SUBSTRING(CONVERT(char(27), @test, 100),14,6),'')

SELECT SUBSTRING(CONVERT(char(27), ISNULL(@test,''), 100),14,6)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform