sql query two dates between 90 days and 7 days

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
venkycool
Participant
Posts: 59
Joined: Fri Feb 16, 2007 12:24 am
Location: USA

sql query two dates between 90 days and 7 days

Post by venkycool »

Hi All,

I am trying to take the result from DW table where I need the record count between last 90 days to last 7 days.

I am trying with this query and am getting the result, but I dont know I am doing the correct one.

My query is SELECT count(1) from table name WHERE etl_timestamp between getdate()-90 and getdate()+7.

Can anyone let me know the query for the above?

Thanks in Advance!
Suriv
No one is perfect... that's why pencils have erasers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Do we have to guess what database? :?

I would assume your "+7" needs to be "-7".
-craig

"You can never have too many knives" -- Logan Nine Fingers
venkycool
Participant
Posts: 59
Joined: Fri Feb 16, 2007 12:24 am
Location: USA

Post by venkycool »

Typo!! I am sorry, it is -7. So the query which am using is correct?

SELECT count(1) from table name WHERE etl_timestamp between getdate()-90 and getdate()-7
Suriv
No one is perfect... that's why pencils have erasers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Probably. Change "select count" to "select *" to check. Add a "not" before the "between" as an additional check of what is being excluded.
-craig

"You can never have too many knives" -- Logan Nine Fingers
venkycool
Participant
Posts: 59
Joined: Fri Feb 16, 2007 12:24 am
Location: USA

Post by venkycool »

Perfect! Saw the difference, query is correct and I got the record count as needed. Thanks chulett!!!
Suriv
No one is perfect... that's why pencils have erasers
Post Reply