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
 Multiple Column searching

Author  Topic 

vikramacharya
Starting Member

3 Posts

Posted - 2011-12-14 : 00:26:48
Hi Currently i am working on sql server 2005
i have a table with 10 column like "company" ,"status" ,"company1", "Status1" and so on .. i want to select the "respected" company with status "selected" by searching in all the columns of company and status.. can i do it in efficient manner without much load on query

something like select *
from Table
where 'selected' in (HRStatus,HRStatus2,HRStatus3,HRStatus4,HRStatus1)
and 'IBM' in (SentTo,SentTo2,SentTo3,SentTo4,SentTo1)

thanks in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-14 : 01:18:27
You need to normalize your table to avoid code like this.

where (hrstatus = 'selected or hrstatus2 = 'selected' or ...) and (sentto = 'ibm' or sentto2 = 'ibm' or ...)

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

Subscribe to my blog
Go to Top of Page

sunnyleoneo
Starting Member

19 Posts

Posted - 2011-12-14 : 01:59:59
please post your table structure also. This will help us to identify whether there is some problem with table structure or not. and we can suggest you proper solution.

Go to Top of Page

vikramacharya
Starting Member

3 Posts

Posted - 2011-12-14 : 02:09:17
Srno as primary Key
Cid (for identification of employee)
Name,
Date,
HRStatus,
HRStatus1,
HRStatus2,
HRStatus3,
HRStatus4,
SentTo,
SentTo1,
SentTo2,
SentTo3,
SentTo4,
Remark,
Remark1,


SentTo's are company names and HRStatus's are the status of the employees
i want to retreive the records with matching company's name with the corresponding HRStatus

i want to show this in single row
Go to Top of Page
   

- Advertisement -