Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Jbalbo
Starting Member
10 Posts |
Posted - 2013-02-14 : 13:35:12
|
Sorry if its in the wrong placeGetting a copnversion error on thisDECLARE @FISCALDATE DATEDECLARE @ENDDATE DATEset @ENDdate = '02/01/2012' SELECT CASE WHEN datepart(MM,@ENDdate)<= 6 THEN CONVERT(datetime, '01-' + '07-'+ (DATEPART(YY, @ENDDATE) -1), 103) --DATEPART(YY, @ENDDATE) -1 ELSE CONVERT(datetime, '01-' + '07-'+ (DATEPART(YY,@ENDDATE)), 103) END AS fiscalDATE BTW what Im trying to do is look at a paramter date (Enddate) then calculate the fiscal year start date from itThanks IN AdvanceJoe |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-14 : 14:10:01
|
[code]DECLARE @FISCALDATE DATEDECLARE @ENDDATE DATESET @ENDdate = '02/01/2012'SELECT CASE WHEN DATEPART(MM, @ENDdate) <= 6 THEN CONVERT(DATETIME, '01-' + '07-' + CAST((DATEPART(YY, @ENDDATE) -1) AS CHAR(4)), 103) --DATEPART(YY, @ENDDATE) -1 ELSE CONVERT(DATETIME, '01-' + '07-' + CAST((DATEPART(YY, @ENDDATE) -1) AS CHAR(4)), 103) END AS fiscalDATE[/code]But it might be simpler to do it this way:[code]DECLARE @ENDDATE DATESET @ENDdate = '02/01/2012'SELECT DATEADD(mm,(DATEDIFF(mm,0,@ENDdate)-6)/12*12+6,0) AS fiscalDate[/code] |
|
|
Jbalbo
Starting Member
10 Posts |
Posted - 2013-02-14 : 16:32:01
|
That is much nicer way than I was thinking Thanks |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-14 : 18:47:04
|
You are very welcome - glad to help. |
|
|
|
|
|
|
|