Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Previous date
Message
 
 
À
11/10/2011 09:06:20
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01526025
Message ID:
01526029
Vues:
72
This message has been marked as the solution to the initial question of the thread.
>I would expect the date
>
>2011-09-11 14:01:37.963
>
>minus 4 years
>
>2007-09-11 14:01:37.963
>
>then the previous 1st October is 2006

I see, I think I misread the original requirement.

In this case:
DECLARE @testdate datetime

SET @testdate = DATEADD(MONTH,-2,CURRENT_TIMESTAMP )
SELECT CASE WHEN RIGHT(CONVERT(VARCHAR(10), @testdate, 112) ,4) >'1001' 
                THEN CONVERT(datetime,LTRIM(YEAR(@testdate)-4) + '1001')

         ELSE CONVERT(datetime,LTRIM(YEAR(@testdate)-5) + '1001') END
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