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)
 select critiria

Author  Topic 

hai
Yak Posting Veteran

84 Posts

Posted - 2009-08-19 : 17:12:00
Trying to filter the record that should not have and 0 on all three( col1,col2, col3) and should be have either value must less then 100 or
greater then 500

This is begin done with 2 statement...got to be a better way to write this:

thanks

delete from tbl1
where (col1 = 0 and col2 =0 and col3= 0)

select col1,col2,col3 from tbl1
where ( col1 not between 100 and 500 )
or ( col2 not between 100 and 500 )
or ( col3 not between 100 and 500 )

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-21 : 02:18:32
You dont need a delete

select col1,col2,col3 from tbl1
where not
(col1 = 0 and col2 =0 and col3= 0)
and
(
( col1 not between 100 and 500 )
or ( col2 not between 100 and 500 )
or ( col3 not between 100 and 500 )
)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -