Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Currently I am working on sql server 2005
i am having a single table with 10 column in which 5 are of "companyName" and 5 for their "HRstatus".
I want that if i select a company and a HRStatus all data with matching records should come..
i have done the code for retreiving with single Hrstatus how can i do it for both..
SQL
select *
from TotTab
where 'Dispatch' in (HRStatus,HRStatus2,HRStatus3,HRStatus4,HRStatus1)
   or 'Rejected' in (HRStatus,HRStatus2,HRStatus3,HRStatus4,HRStatus1)



i want the query that will match the "companyName" with "hrstatus"

any1 plz suggest


thanks in advance
Vikram Acharya
Posted
Updated 13-Dec-11 20:43pm
v2

If possible, you should change the design of the database. Do not store repeating data in different columns, store them on different rows. So organize the tables so that you have the company name in a single column and hrstatus in another column. Possibly if you need you can have other columns to categorize the rows (for example orderno if the company names or statuses are ordered etc).

Addition, normalization:
The correct way to normalize your table depends on several factors but to get something to start with, could you consider something like:
Employee
- Srno as primary Key
- Cid (for identification of employee)
- Date,
- Name,
- ContactNumber,
- DOB,
- Age,
- Location,
- Qualification,

EmployeeHRStatus
- Srno (foreign key to Employee)
- HRStatus,
- StatusDate

EmployeeSentTo
- Srno (foreign key to Employee)
- SentTo,
- SentToDate

etc.
 
Share this answer
 
v2
Comments
Acharya Vikram 14-Dec-11 2:36am    
Thanks 4 your reply
Actually I know the importance of normalization in the database structure and based on that I have done that before by making two tables but in my case its the need of client and situation are such that made me to make one table.
below are my fields can you help me in normalizing it..

Srno as primary Key
Cid (for identification of employee)
Date,
Name,
ContactNumber,
DOB,
Age,
Location,
Qualification,

HRStatus,
HRStatus1,
HRStatus2,
HRStatus3,
HRStatus4,
SentTo,
SentTo1,
SentTo2,
SentTo3,
SentTo4,
Remark,
Remark1

i have to show them as one...
thanx in advance
Wendelius 14-Dec-11 2:46am    
Answer updated
Amir Mahfoozi 14-Dec-11 2:50am    
+5 ;)
Wendelius 14-Dec-11 2:55am    
Thank you :)
Acharya Vikram 14-Dec-11 3:26am    
Thanx 4 ur help...
SQL
select *
from TotTab
where ('your_status_condition' = HRStatus1 AND 'your_company_name' = Companyname1) OR ('your_status_condition' = HRStatus2 AND 'your_company_name' = Companyname2) OR ('your_status_condition' = HRStatus3 AND 'your_company_name' = Companyname3)OR ('your_status_condition' = HRStatus4 AND 'your_company_name' = Companyname4)
OR ('your_status_condition' = HRStatus5 AND 'your_company_name2' = Companyname5)   

I'm not sure if i understood your question right and i'm just a beginner but i wanted to try to help
 
Share this answer
 
Comments
Acharya Vikram 16-Dec-11 2:28am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900