September 20, 2006 at 11:40 am
I have two tables, the first of which is a summary table, the second is a detail table. I'd like to be able to come up with a T-SQL statment that I can use in a package that will read the first table, find all matches of a key field in the second table, concatenate the values of a text field in the second table, and then update a field in the first table with the concatenated text.
Said another way, read one, find multiple matches in the second table, gather up all the text in one field, and then update the first table.
Thanks for any suggestions
September 20, 2006 at 12:17 pm
Without knowing the structure of your tables or the data contained, a little difficult to help come up with the solution you are looking for, however, I hope the following code will help you in your search for a solution:
declare @table1 table (
Ident int,
CharVal char(1)
)
declare @table2 table (
Ident int,
CharVals varchar(20)
)
insert into @table1 (Ident, CharVal) values (1,'A')
insert into @table1 (Ident, CharVal) values (2,'B')
insert into @table1 (Ident, CharVal) values (3,'C')
insert into @table1 (Ident, CharVal) values (1,'D')
insert into @table1 (Ident, CharVal) values (1,'E')
insert into @table1 (Ident, CharVal) values (2,'F')
insert into @table1 (Ident, CharVal) values (3,'G')
declare @CharVals varchar(20)
set @CharVals = ''
select @CharVals = @CharVals + CharVal + '~' from @table1 where Ident = 1
select @CharVals
September 20, 2006 at 12:27 pm
I hope this is what u are looking for:
Declare @fname varchar(2000)
set @fname=''
Select @fname = @fname + fname + ',' from pubs.dbo.employee
where Job_id = 13
Select @fname
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply