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
 help needed in implemeting this logic

Author  Topic 

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2011-11-17 : 14:44:52
hi,

I have two tables as follows.

Table Name : Users

user_id firstName lastName email address representative

1 ross taylor rts@gmail.com hhmc

2 not Assigned pbc@yahoo.com icmc


Table Name : Request

RequestId representative1 representative2

1 hhmc icmc

my codiiton here is if firstname+lastName ="NotAssigned" then choose emailaddress belongs to hhmc else choose emailaddress belongs to icmc.

by joiing both the query my out put will be as follows by putting requset_id as a input parameter from front end.


1 hhmc icmc rts@gmail.com

purposely i want to do this using sql query. i know that using stored proc it is vry simple. is ther any way of doing this by sql query

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-11-17 : 15:05:39
Something like
SELECT u.userid,u.firstName,u.lastname
,[email] = case when u.firstName+u.lastname = 'NotAssigned' then r.hhmc else r.icmc end
FROM
Users U
INNER JOIN
Request r on u.user_id = r.requestid (i'm not sure how these tables actually join)

Jim



Everyday I learn something that somebody else already knew
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2011-11-17 : 15:25:33
thanks jim i got few idea from your answer
Go to Top of Page
   

- Advertisement -