Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert multiple records into one field? 1

Status
Not open for further replies.

christer99

IS-IT--Management
Dec 3, 2001
247
How would I insert multiple records from one table into one field/column into another table. When I ran the query below I am only get the first value inserted and not all of them

update roundingtype
set pccodes = pccodes+' '+ a.type from (

SELECT top 500 TYPE
FROM POLICY
WHERE (TYPEGROUP = 'PC') AND (STATUS IN ('NEW', 'REN', 'END', 'REW')) AND (RIGHT(EXP, 2) IN ('A5', 'A6', 'A7'))
GROUP BY TYPE
ORDER BY TYPE) a
 
Try
Code:
declare @fieldlist varchar(2000)
SET @fieldlist = ''
select top 500 @fieldlist = @fieldlist + convert(varchar,TYPE)+ ' ' FROM         POLICY
WHERE     (TYPEGROUP = 'PC') AND (STATUS IN ('NEW', 'REN', 'END', 'REW')) AND (RIGHT(EXP, 2) IN ('A5', 'A6', 'A7'))
GROUP BY TYPE
ORDER BY TYPE

update roundingtype
set pccodes = pccodes + @fieldlist

"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top