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
 Get ditinct data if all 3 criteria is satisfied?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-02-11 : 10:01:42
Hi

I have table with 25 colums. 3 of the colums(Chkflag,BMCHECK,UPDATED) have yes/no data type.
What I am trying to do :
If chkflag is No value (i.e 0) and BMCHECK or UPDATED has no value then bring one of the field from BMCHECK.

quote:
SELECT DISTINCT BMCHECK FROM FEEDER WHERE Chkflag = 0 AND BMCHECK = 0 OR UPDATED = 0


I am using the above query in vb.net to look for any of above field is blank or not ticked if the query brings any data THEN
---run the other queries
else (There is no data)
---do this---

Advance thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-11 : 10:04:05
Learn OPERATOR presedence.

SELECT DISTINCT BMCHECK FROM FEEDER WHERE Chkflag = 0 AND (BMCHECK = 0 OR UPDATED = 0)


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-11 : 10:05:41
Or this suggestion
SELECT DISTINCT	BMCHECK
FROM FEEDER
WHERE Chkflag = 0
AND 0 IN (BMCHECK, UPDATED)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-11 : 10:17:53
Or
SELECT DISTINCT BMCHECK
FROM FEEDER
WHERE Chkflag = 0
AND CAST(BMCHECK AS int) + CAST(UPDATED AS int) >0
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-02-11 : 10:25:01
Thanks a lot it works.

quote:
Originally posted by Peso

Or this suggestion
SELECT DISTINCT	BMCHECK
FROM FEEDER
WHERE Chkflag = 0
AND 0 IN (BMCHECK, UPDATED)



E 12°55'05.25"
N 56°04'39.16"


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-12 : 01:03:06
quote:
Originally posted by Vaishu

Hi

I have table with 25 colums. 3 of the colums(Chkflag,BMCHECK,UPDATED) have yes/no data type.
What I am trying to do :
If chkflag is No value (i.e 0) and BMCHECK or UPDATED has no value then bring one of the field from BMCHECK.

quote:
SELECT DISTINCT BMCHECK FROM FEEDER WHERE Chkflag = 0 AND BMCHECK = 0 OR UPDATED = 0


I am using the above query in vb.net to look for any of above field is blank or not ticked if the query brings any data THEN
---run the other queries
else (There is no data)
---do this---

Advance thanks


You need to be very careful when using AND and OR in where clause
As suggested use proper paranthesis to avoid any improper result

Madhivanan

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

- Advertisement -