I have a table UserMaster
as follow...(only required columns are shown)
UserID UserName EmailID
---------------------------------
1000 amol amol@gmail.com
1001 mahesh mahesh@gmail.com
1002 saurabh saurabh@gmail.com
1003 nitesh nitesh@gmail.com
Another table MessageHistory
(Only required columns are shown)
MsgCode From To
-----------------------------
MSG001 1000 1001,1002,1003
MSG002 1001 1000,1002,1003
I am storing UserIds
in From
and To
columns...
I am trying to create a stored procedure to display the Email History
of particular message code
Create Procedure proc_GetMessageHistory
@MsgCode varchar(50)
as
Begin
Select * From MessageHistory Where MsgCode=@MsgCode
End
The result is coming as shown above in MessageHistory
table...but I want to show respective UserEmailIDs
instead of UserID
(e.g. 'amol@gmail.com' instead of 1000)...
How could I do this in a stored procedure? How could I use inner join in this case specially with comma-separated values? Please help...thanks