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.
| Author |
Topic |
|
raghunathan
Starting Member
2 Posts |
Posted - 2008-08-04 : 01:49:13
|
| Hi Please advice me to solve the sqlserver 2005 queryMy Criteria is...Retreive data from db such that it should satisfy the following conditionEither EQUAL to 0OrNot EQUAL to 0 -------------------------uid name approved_by 1 abc 0 1 sf 0 1 sdaf 20 1 sdaf 42-------------------------I need a single query to solve this issue......my result set should be when APPROVED_By = 0 1 abc 0 1 sf 0and when APPROVED_By <> 0 1 sdaf 20 1 sdaf 42 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-08-04 : 02:18:36
|
| SELECTuid,[name],approved_byFROM YourTableWHERE approved_by = 0SELECTuid,[name],approved_byFROM YourTableWHERE approved_by != 0Webfred |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-08-04 : 03:35:48
|
| I'm confused. If approved_by is either equal to zero or not equal to zero then doesn't that make it a redundant check?Unless you mean WHERE APPROVED_BY IS NOT NULL which is the only thing I can think of other than having no WHERE clause at all. |
 |
|
|
padamgondenk2001
Starting Member
4 Posts |
Posted - 2008-08-04 : 03:52:03
|
| U will use following Query,Select ..,...,.., from ........ where APPROVED_By != 0Padamgonde N. KSoftware Developer,HOL Infosolution Pvt. Ltd.Pune, India |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 03:59:01
|
Lozt is right, what you've asked for doesn't really make sense, other than maybe if you actually want a case expression in there somewhere? like...SELECT uid ,[name] ,case when approved_by <> 0 then 'Approved' else 'Not Approved' end as Approved_or_notFROM YourTable Em |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-04 : 10:45:45
|
quote: Originally posted by raghunathan Hi Please advice me to solve the sqlserver 2005 queryMy Criteria is...Retreive data from db such that it should satisfy the following conditionEither EQUAL to 0OrNot EQUAL to 0 -------------------------uid name approved_by 1 abc 0 1 sf 0 1 sdaf 20 1 sdaf 42-------------------------I need a single query to solve this issue......my result set should be when APPROVED_By = 0 1 abc 0 1 sf 0and when APPROVED_By <> 0 1 sdaf 20 1 sdaf 42
i think what you want is an extra parameter to retrieve approved or not approved records. just name it Approved. then you can use like thisSELECT uid, name, approved_byFROM YourTableWHERE (@Approved=APPROVED_By) OR (APPROVED_By <> 0 AND @Approved=1) |
 |
|
|
|
|
|
|
|