January 4, 2013 at 9:03 pm
Oh i get it already. So which one is recommended? Better performance maybe? THanks to the two pros!
January 9, 2013 at 1:10 am
[/b]
So if i have an sql statement in my execute sql task that looks something like this:
Delete from TABLE where (CREATION_D = ?)
CREATION_D is the column i am discussing about. So if i use it as datetime it will give me values such as 1/4/2013 12:00:00 AM while ? is a parameter from my package variable (ExecDate) of a datatype varchar that will look like 1/4/2013 11:38:00 AM. I want that delete statement to be triggered when both are of same date. How shall i edit to achieve this? Thanks for all the inputs, i decided to heed all advice and remain my CREATION_D as datetime datatype
Hi pros,
i would like to ask if i decide not to use the varchar variable... but given the same scenario how can i perform DELETE FROM TABELE WHERE CREATION_D = todayDateWithoutTime?
Which means i compare if the two dates are the same, regardless of the time, i shall delete..
Am i doing it right?
DELETE FROM RPT_TAPS_DTL
WHERE (DATEADD(DAY, DATEDIFF(DAY, CAST('19000101' AS DATETIME), CREATION_D), CAST('19000101' AS DATETIME)) = DATEADD(DAY, DATEDIFF(DAY,
CAST('19000101' AS DATETIME), GETDATE()), CAST('19000101' AS DATETIME)))
January 9, 2013 at 4:48 am
10e5x (1/9/2013)
[/b]
So if i have an sql statement in my execute sql task that looks something like this:
Delete from TABLE where (CREATION_D = ?)
CREATION_D is the column i am discussing about. So if i use it as datetime it will give me values such as 1/4/2013 12:00:00 AM while ? is a parameter from my package variable (ExecDate) of a datatype varchar that will look like 1/4/2013 11:38:00 AM. I want that delete statement to be triggered when both are of same date. How shall i edit to achieve this? Thanks for all the inputs, i decided to heed all advice and remain my CREATION_D as datetime datatype
Hi pros,
i would like to ask if i decide not to use the varchar variable... but given the same scenario how can i perform DELETE FROM TABELE WHERE CREATION_D = todayDateWithoutTime?
Which means i compare if the two dates are the same, regardless of the time, i shall delete..
Am i doing it right?
DELETE FROM RPT_TAPS_DTL
WHERE (DATEADD(DAY, DATEDIFF(DAY, CAST('19000101' AS DATETIME), CREATION_D), CAST('19000101' AS DATETIME)) = DATEADD(DAY, DATEDIFF(DAY,
CAST('19000101' AS DATETIME), GETDATE()), CAST('19000101' AS DATETIME)))
It will work but this is how I would do it:
delete from RPT_TAPS_DTL
where
CREATE_D >= dateadd(dd,datediff(dd,cast('19000101' as datetime),getdate()),cast('19000101' as datetime)) and
CREATE_D < dateadd(dd,datediff(dd,cast('19000101' as datetime),getdate()) + 1,cast('19000101' as datetime));
January 9, 2013 at 6:46 am
Cadavre (1/4/2013)
10e5x (1/4/2013)
omg i am losing the discussion over here... so the recommended solution to me is which? And is it a typo or? why there are two '??' sry for the noobness and confusionEither would work, I think Lynn was just showing you a different way to achieve the result. The two "?" is for your parameter.
DELETE FROM TABLE WHERE (CREATION_D = DATEADD(DAY, 0, DATEDIFF(DAY, 0, @yourDateParamater )));
DELETE FROM TABLE WHERE (CREATION_D = DATEADD(DAY, DATEDIFF(DAY, 0, @yourDateParamater ), 0));
Another way would be to do this: -
DELETE FROM TABLE WHERE (CREATION_D = CAST(DATEDIFF(DAY, 0, @yourDateParamater ) AS DATETIME));
I think they're all roughly equivalent in terms of performance.
Careful now. I realize that Lynn has already pointed it out but I want to emphasize it... The example that Lynn gave is the correct one (the second one above). "0" is a date here and the correct syntax of DATEADD is DATEADD(<datepart>, <numberofparts>, <date/time>). It can really make a difference depending on what you're doing.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 9, 2013 at 5:26 pm
Careful now. I realize that Lynn has already pointed it out but I want to emphasize it... The example that Lynn gave is the correct one (the second one above). "0" is a date here and the correct syntax of DATEADD is DATEADD(<datepart>, <numberofparts>, <date/time>). It can really make a difference depending on what you're doing.
Thanks Jeff, noted, I got it.
January 11, 2013 at 3:15 am
Jeff Moden (1/9/2013)
Careful now. I realize that Lynn has already pointed it out but I want to emphasize it... The example that Lynn gave is the correct one (the second one above). "0" is a date here and the correct syntax of DATEADD is DATEADD(<datepart>, <numberofparts>, <date/time>). It can really make a difference depending on what you're doing.
I may be being dense, but can you give me an example?
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply