I have a table UserMaster
as follow...(only required columns are shown)
UserID UserName EmailID
---------------------------------
1000 amol [email protected]
1001 mahesh [email protected]
1002 saurabh [email protected]
1003 nitesh [email protected]
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. '[email protected]' 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