Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making a choice in where clause statement

Status
Not open for further replies.

sivi

IS-IT--Management
Nov 27, 2002
27
GB
Hi
I need to select records which were updated previous working day. This means if today is a Monday, I need to select records which were updated on Friday and not yesterday, which will be a Sunday.

I am using WHERE clause to get the previous day, but how can I do a selection whithin a WHERE clause to check if previous day was Mon-Fri or if today is 'Mon' then select the records which were updated 2 days before, otherwise select the records which were updated previous day.

Can I use IF statement in SQL 2000.

I would appreciate any help.

Thanks, Sivi

 
Something like this:

Declare @ValueDate AS DateTime
Declare @BackDatedDate AS DateTime
Declare @BackDays AS integer

set @BackDatedDate = getdate()


Set @BackDays = CASE DATENAME(weekday, @BackDatedDate)
WHEN 'Sunday' THEN 2
WHEN 'Saturday' THEN 1
ELSE 0
END
Set @ValueDate = @BackDatedDate -@BackDays

select @valuedate

by setting the @Backvaluedateddate to for instance yesterday (getdate()-1) you can see that the valuedate that gets returned will be friday.

Regards,

Atomic Wedgie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top