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 |
|
LOLCatLady
Starting Member
24 Posts |
Posted - 2011-04-15 : 11:58:43
|
This section of code is in a query I inherited to pull a mailing list based on criteria to identify different segments. It's obviously date related but can someone please explain to me what it's doing?declare @startFY smalldatetime set @startFY = case when month(@today)>='3' then '3/1/'+ cast(YEAR(@today) AS varchar(4)) else DATEADD(yy,-1, '3/1/'+ cast(YEAR(@today) as varchar(4))) enddeclare @endMinus1 smalldatetime set @endMinus1 = cast('3/1/' + CAST(YEAR(@today) AS varchar(4)) as datetime) Thanks! |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-04-15 : 12:06:53
|
| case when month(@today)>='3' then '3/1/'+ cast(YEAR(@today) AS varchar(4))else DATEADD(yy,-1, '3/1/'+ cast(YEAR(@today) as varchar(4))) endset @startFY toIf the month is not jan feb or mar then use 3/1/ of current year else previous year. I presume you are using US date format so will be the 1 march this year or last year.So it is the previous 1 mar from @today@endMinus1 is set to 1 march of the current year.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
LOLCatLady
Starting Member
24 Posts |
Posted - 2011-04-15 : 12:16:48
|
| The date format is US. Thank you for your help. I've got several complex queries and I'm trying to understand each of the components before I attempt to simplify them. |
 |
|
|
|
|
|