From: Himansu on
Hello everyone,

I'm trying to get records BEFORE 6 months ago based on 2 date feilds.
Here's the script:


if object_id('tempdb.dbo.#hha') > 0 drop table #hha
select *
into #hha
from temp.dbo.op with (nolock)
where
(Date1 < DATEADD(MONTH, -6, GETDATE())
and Date1 <> '1900-01-01 00:00:00')
or
(Date2 < DATEADD(MONTH, -6, GETDATE())
and Date2 <> '1900-01-01 00:00:00')


*After executing the script and looking the data in the temp table I don't
think the logic is correct. What do you guys think? Any help will be
greatly appriciated.

Thankas,
Himansu


From: Scott Morris on

"Himansu" <himansu114(a)hotmail.com> wrote in message
news:OyHNz0B0KHA.6140(a)TK2MSFTNGP05.phx.gbl...
> Hello everyone,
>
> I'm trying to get records BEFORE 6 months ago based on 2 date feilds.
> Here's the script:
>
>
> if object_id('tempdb.dbo.#hha') > 0 drop table #hha
> select *
> into #hha
> from temp.dbo.op with (nolock)
> where
> (Date1 < DATEADD(MONTH, -6, GETDATE())
> and Date1 <> '1900-01-01 00:00:00')
> or
> (Date2 < DATEADD(MONTH, -6, GETDATE())
> and Date2 <> '1900-01-01 00:00:00')
>
>
> *After executing the script and looking the data in the temp table I don't
> think the logic is correct. What do you guys think? Any help will be
> greatly appriciated.

Show an example of a row that you do not believe should be included - or a
row that is missing that should have been included. Incidentally, you have
already been reminded that the logic used will not include all rows from the
last date of the period since it is based on the current date AND time.
For further clarification on datetime usage, refer to:

http://www.karaszi.com/sqlserver/info_datetime.asp


From: Tom on
On Mar 30, 11:25 am, "Himansu" <himansu...(a)hotmail.com> wrote:
> Hello everyone,
>
> I'm trying to get records BEFORE 6 months ago based on 2 date feilds.
> Here's the script:
>
> if object_id('tempdb.dbo.#hha') > 0 drop table #hha
> select *
> into #hha
> from temp.dbo.op with (nolock)
> where
> (Date1 < DATEADD(MONTH, -6, GETDATE())
> and Date1 <> '1900-01-01 00:00:00')
> or
> (Date2 < DATEADD(MONTH, -6, GETDATE())
> and Date2 <> '1900-01-01 00:00:00')
>
> *After executing the script and looking the data in the temp table I don't
> think the logic is correct.  What do you guys think?  Any help will be
> greatly appriciated.
>
> Thankas,
> Himansu

This looks good to me. What did you see that made you think it was not
working?
 | 
Pages: 1
Prev: SQL2008 > SQL2000
Next: joins and trusted FKs