Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 RESOLVED - Dataadd where clause - Quick Question

Author  Topic 

darms21
Yak Posting Veteran

54 Posts

Posted - 2012-08-10 : 11:14:57
I want to show all records except those where the status is 'delivered' AND update date is more than 1 day ago.

Having trouble....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 11:19:18
just convert your statement to sql and you're done

WHERE status='delivered'
and updatedate< dateadd(dd,datediff(dd,0,getdate()),-1)


see date logic explained here

http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

darms21
Yak Posting Veteran

54 Posts

Posted - 2012-08-10 : 11:19:21
Never mind, I got it:


SELECT *
FROM TEST
where status not like 'delivered' or (status like 'delivered' and
update_date > dateadd(day, -1, getdate()))

order by hstatus, update_date
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 11:22:04
update date is more than 1 day ago

do you mean from 1 day ago forward or backward?



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -