suresh

suresh

  • NA
  • 293
  • 0

How to select values

Mar 4 2012 10:40 AM

Hi,

If(@username='Ram')
Begin
Select Professor,Stu_name,Location,Subject From student where Location in('Hyderabad','Banglore','Chennai')
End
Else if(@username='Krishna')
Begin
Select Professor,Stu_name,Location,Subject From student where Location in('Pune','Mumbai','Kolkata')
End

Ii don't need to to Hard code like above..
I want logic like , if user logined with ram..i need to set Location,if user logined withkrishna ..i need to set Location... 

by using SET we can set only one value at a time for a variable...so i need to set multiple values for Location variable when user logined with that particular username..how can i do it...

@Declare @location varchar(20)
If(@username='Ram')
Begin
set @location='Hyderabad','Banglore','Chennai'
end
Else if(@username='krishna')
Begin
set @location='Chennai','Pune','Mumbai'
End


Select Professor,Stu_name,Location,Subject From student where Location=@location


So i want logic like above ....

Please Help me


Answers (1)