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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to Solve This

Author  Topic 

compguyy
Starting Member

1 Post

Posted - 2008-03-24 : 10:17:14
Help me out how to solve this requirement

Table_1
Col1 Col2 Col3 Col4
1 101 Usr1 WRK1
2 101 Usr2 WRK1

Table_2
Col1 Msg
101 User %1 Logged on %2

Expected Output

User Usr1 logged on WRK1
User Usr2 logged on WRK1

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-03-24 : 10:30:32
Select 'User' + '' + Table_1.Col3 + 'logged on'+ '' + Table_1.Col4 as Output from Table_1 inner join Table_2 on Table_1.col2=Table_2.col1
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-24 : 10:33:15
[code]declare @t1 table
(
col1 int,
col2 int,
col3 varchar(10),
col4 varchar(10)
)

declare @t2 table
(
col1 int,
msg varchar(50)
)

insert @t1
select 1, 101, 'Usr1', 'WRK1' union all
select 2, 101, 'Usr2', 'WRK1'

insert @t2
select 101, 'User %1 Logged on %2'


select replace(replace(t2.msg, '%1', t1.col3), '%2', t1.col4)
from @t1 t1 join @t2 t2 on t1.col2 = t2.col1[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -