Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an employee table with fields EmpId , EmpName , DeptID , Salary , EditedOn, EditedBy and Address .It has following entries:

SQL
EmpId   EmpName DeptID  Salary  EditedBy EditedOn       Address
1	Sonia	2	25000	1	2015-02-10	NULL
2	Rahul	1	15000	1	2015-01-10	NULL
3	Pooja	3	12000	1	2015-04-05	NULL
5	Tanya	7	32000	1	2015-04-10	NULL
6	Raj	8	27000	1	2015-04-03	NULL
16	NULL	1	NULL	NULL	2015-04-15	NULL
17	NULL	1	NULL	NULL	2015-04-15	NULL
18	NULL	1	NULL	NULL	2015-04-15	NULL
19	Roshni 	NULL	NULL	NULL	NULL	        Vasco
27	gh	NULL	NULL	NULL	NULL	        kk
28	Priyanka 	7000	NULL	NULL		Porvorim 
29	Ramesh 	NULL	NULL	NULL	NULL	        Vasco 

I want to create a strored procedure proc_GetEmployeeOnSalaryrange and specify foll conditions :
SQL
if salary is between ( 0-10000) 
Select EmpName, Salary , 'Range A' 
Else if salary is between ( 10001-20000)
Select EmpName, Salary , 'Range B' and third condition is :
if salary is above 20000 
Select EmpName, Salary , 'Range C'

and Range A , Range B and Range C should be hard coded . I dont know the if else syntax to be used. so please help .
Posted
Updated 16-Apr-15 20:22pm
v2
Comments
Thanks7872 16-Apr-15 2:15am    
This is just a list of requirement. Where is the question? What have you tried so far?
Member 11601994 17-Apr-15 3:25am    
I was able to get the output on my own .

Try this:
SQL
Select EmpName, CASE WHEN Salary > 0 AND Salary <=10000 THEN ' A'
                     WHEN Salary > 10000 AND Salary <20000 THEN 'B'
                     WHEN Salary > 20000 THEN 'C'
                END AS RangeOfSalary


See: CASE ... (SQL)[^]
 
Share this answer
 
Hi there, you need to look at *case* statement
 
Share this answer
 
Comments
Member 11601994 16-Apr-15 2:14am    
Hi. can u show me the syntax using case statement for my question ?
Thanks7872 16-Apr-15 2:15am    
You can see it using google.

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