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)
 How to filter without the where clause?

Author  Topic 

pras2007
Posting Yak Master

216 Posts

Posted - 2009-12-15 : 23:40:16
Hello All,

I want to be able to filter out records that has 0 for the sys_insert field without specifying it in the where clause, how can this be done?

If I multiple the values for the ID field to the sys_insert field I get values where the sys_insert field is 1. The problem with this method is that 0 values are showing, how can I 0 values be filter out in the result set?

Sample table:
ID Sys_Insert
100 0
100 1
100 0
100 1
200 1
200 1
300 0
300 0
500 1

select distinct (id * sys_insert) AS LDS from test

should be:
LDS
100
200
500

Instead of:
LDS
0
100
200
500

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-16 : 01:59:54
Why do you not want to specify it in the where clause?

Madhivanan

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

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-12-16 : 18:15:54
you could do something silly like

SELECT id * sys_insert
from yourTable
group by id * sys_insert
having id * sys_insert > 0

but where sys_insert > 0 makes a lot more sense

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2009-12-17 : 11:24:30
select id * sys_insert AS LDS from test
except
select 0
Go to Top of Page
   

- Advertisement -