Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cast() within isnull or outside?
Message
De
14/09/2007 12:47:52
 
 
À
14/09/2007 12:37:11
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01254374
Message ID:
01254378
Vues:
19
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform