Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
From 112 to DATEPART
Message
 
 
À
24/01/2011 20:58:57
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01497298
Message ID:
01497300
Vues:
53
This message has been marked as the solution to the initial question of the thread.
>I have this:
>
>
>SELECT CONVERT(CHAR(8),Hit.AddDate,112)
>
>
>It is good to return a 20110124 syntax. Now, I have another situation where I have pretty much the same query but I need to add two additional digits representing the hour. Basically, it goes like this:
>
>
>SELECT CONVERT(CHAR(4),YEAR(Hit.AddDate))+REPLACE(STR(MONTH(Hit.AddDate),2),' ','0')+
> REPLACE(STR(DAY(Hit.AddDate),2),' ','0')+REPLACE(STR(DATEPART(HOUR,Hit.AddDate),2),' ','0')
>
>
>What would be the replacement of 112 to obtain a syntax like 2011012412, which would represent the 12th hour for example.

Try
SELECT CONVERT(CHAR(8),Hit.AddDate,112) + CONVERT(CHAR(2), Hit.AddDate,108)
BTW, in SSMS highlight CONVERT and Press F1. It will give you all formats available for CONVERT.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform