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
 Sqlserver query

Author  Topic 

raghunathan
Starting Member

2 Posts

Posted - 2008-08-04 : 01:49:13
Hi Please advice me to solve the sqlserver 2005 query
My Criteria is...

Retreive data from db such that it should satisfy the following condition

Either EQUAL to 0
Or
Not 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 0

and

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
SELECT
uid,
[name],
approved_by
FROM YourTable
WHERE approved_by = 0

SELECT
uid,
[name],
approved_by
FROM YourTable
WHERE approved_by != 0

Webfred
Go to Top of Page

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.
Go to Top of Page

padamgondenk2001
Starting Member

4 Posts

Posted - 2008-08-04 : 03:52:03
U will use following Query,
Select ..,...,.., from ........ where APPROVED_By != 0



Padamgonde N. K
Software Developer,
HOL Infosolution Pvt. Ltd.
Pune, India
Go to Top of Page

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_not
FROM YourTable





Em
Go to Top of Page

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 query
My Criteria is...

Retreive data from db such that it should satisfy the following condition

Either EQUAL to 0
Or
Not 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 0

and

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 this


SELECT uid, name, approved_by
FROM YourTable
WHERE (@Approved=APPROVED_By)
OR (APPROVED_By <> 0 AND @Approved=1)
Go to Top of Page
   

- Advertisement -