August 17, 2015 at 6:14 am
DECLARE @Date
SET @Date = 2012
DECLARE @Year int
SET @Year = (SELECT DATEPART(yyyy,@Date))
SELECT @Year AS Year
--SELECT *
-- FROM [Orders].[dbo].[Orders] od
-- WHERE .Orderl_Date < @Date;
----WHERE DATEPART(yyyy,@Date)= @Year
----WHERE DATEPART(yyyy,od.Order_Date)= @ArchiveYear
August 17, 2015 at 6:18 am
Duplicate post. No replies please
Replies to http://www.sqlservercentral.com/Forums/Topic1712220-3077-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 17, 2015 at 6:19 am
you want to leave the column alone, without functions or conversions, so you can use any existing indexes.
instead, generate the dates the date values should be in between:
DECLARE @Date datetime --use a proper date!
SET @Date =getdate() --august 17 of this year
SELECT *
FROM [Orders].[dbo].[Orders] od
WHERE Orderl_Date >= DATEADD(yy, DATEDIFF(yy,0,@Date), 0) --jan 1 of the year of the date param passed.
AND Orderl_Date < DATEADD(yy,1,DATEADD(yy, DATEDIFF(yy,0,@Date), 0)) --add one year: jan 1 of following year
Lowell
August 17, 2015 at 6:21 am
Chris.Hubbard4U (8/17/2015)
DECLARE @DateSET @Date = 2012
DECLARE @Year int
SET @Year = (SELECT DATEPART(yyyy,@Date))
SELECT @Year AS Year
--SELECT *
-- FROM [Orders].[dbo].[Orders] od
-- WHERE .Orderl_Date < @Date;
----WHERE DATEPART(yyyy,@Date)= @Year
----WHERE DATEPART(yyyy,od.Order_Date)= @ArchiveYear
Here's one way:
declare @Year int = 2012
declare @StartDate date = datefromparts(@Year, 1, 1)
declare @EndDate date = datefromparts(@Year + 1, 1, 1)
select
from
where [date] >= @StartDate and [date] < @EndDate
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 17, 2015 at 6:22 am
GilaMonster (8/17/2015)
Duplicate post. No replies pleaseReplies to http://www.sqlservercentral.com/Forums/Topic1712220-3077-1.aspx
Oops, didn't see this in time.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 17, 2015 at 7:53 am
GilaMonster (8/17/2015)
Duplicate post. No replies pleaseReplies to http://www.sqlservercentral.com/Forums/Topic1712220-3077-1.aspx
Sorry it was an accident.:blush:
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply