Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Convert This Date
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01448391
Message ID:
01448392
Vues:
46
>I have 96K rows with a Month column. The data is in the format:
>
>
YYYY-MM-Mon
>
>So, '2009-11-Nov' is November, 2009 and '2009-02-Feb' is February. The middle 2 charaters are the month number.
>
>I need to convert these to the first Saturday of the month. Anyone know of a way to do this?
SET DATEFIRST 7
DECLARE @TestMe varchar(20)
SET @TestMe = '2009-11-Nov'
DECLARE @TestDate as Datetime
SET @TestDate = LEFT(REPLACE(@TestMe,'-',''),6)+'01'
SELECT @TestDate,
       DATEPART(dw, @TestDate) AS DayOfWeek,
       DATEADD(dd,7-DATEPART(dw, @TestDate),@TestDate) AS FirstSaturday
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
Répondre
Fil
Voir

Click here to load this message in the networking platform