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
 General SQL Server Forums
 New to SQL Server Programming
 Query

Author  Topic 

mukhan85
Starting Member

46 Posts

Posted - 2008-12-24 : 12:35:39
Hi I think that the following query returns all rows that have Status equal to '0' or '4'
is it correct?

select Task_id
FROM Task
WHERE
(
Status NOT IN (0,4)
OR CONVERT(char(4),DATEADD(second, Create_Date, '1969-12-31 8:00:00 PM'),112) >= '2006'
OR CONVERT(char(4),DATEADD(second, Actual_End_Date, '1969-12-31 8:00:00 PM'),112) >= '2006'
)
AND Category IN ('CRI','RFD')

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-24 : 12:45:30
Does it return the correct results?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-12-24 : 12:45:47
The query will return all rows where the status is not 0 or 4, the create is >= 2006 or
the actual_end_date >= 2006. So if the create_date is in 2007, you will get all statuses associated with it

Jim
Go to Top of Page

mukhan85
Starting Member

46 Posts

Posted - 2008-12-24 : 14:13:09
quote:
Originally posted by jimf

The query will return all rows where the status is not 0 or 4, the create is >= 2006 or
the actual_end_date >= 2006. So if the create_date is in 2007, you will get all statuses associated with it

Jim


But if Create >= 2006 then, it won't look even if Status is 0 or 4, so it will return all tickets that satisfy Create >= 2006 and Actual_end_date >= 2006 even if Status is 0 or 4 and those whose Status is 0 or 4 but won't look at Dates'
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-24 : 23:42:45
Hi,

Please post table structure , sample data and expected o/p so that we can give a query which is apt for u...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-25 : 01:34:16
you still didnt tell us what's your exact reqmnt. can you please explain what you want?
Go to Top of Page
   

- Advertisement -