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)
 Help on query??

Author  Topic 

krish001
Yak Posting Veteran

61 Posts

Posted - 2009-12-18 : 15:07:04
select Number from AGENT_HIERARCHY
where level1 = '1'

By this quer i get Number when '1' is there in column(level1) but my problem is there are more levels like level2,level3,level4,level5
and i need to check for '1' in each and every columns(level2,level3,level4,level5) is present or not????

How can i solve this.....plz help

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-18 : 15:11:57
You've got a design issue. Because of that, you'll have to do a query like this:

select Number from AGENT_HIERARCHY
where level1 = '1' OR level2 = '1' OR level3 = '1' OR ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-20 : 04:12:36
as tkizer pointed out it would have been better if you had a single column level containing values 1,2,3... and each level data will be represented by a new row
Go to Top of Page
   

- Advertisement -