Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
How to Achieve this Result,Can Anyone help me for query in Ms Sqlserver


1st Table Emp
-----------------------
EId Name Age
1 A 15
2 B 25
3 C 45

2nd Table AgeDetails
------------------------
Aid AgeGroup MinAge MaxAge
1 young 1 17
2 Adult 18 40
3 Older 41 60

Result
-----------------
EId Name AgeGroup
1 A Young
2 B Adult
3 C older


Thanks...
Posted

Select
SQL
Name,AgeGroup
From Emp Inner Join AgeDetails
On Emp.Age Between MinAge And MaxAge
 
Share this answer
 
v2
select Emp.EID,Emp.Name,AgeDetails.AgeGroup from Emp where Emp.Age between AgeGroup.MinAge and Agegroup.Maxage
 
Share this answer
 
SQL
SELECT e.eid,e.Name,ag.AgeGroup
FROM emp e, AgeDetails ag
WHERE e.age between ag.min and ag.max

Enjoy..
 
Share this answer
 

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