Morning,I'm trying to combine field values into one line.I used the post http://www.sqlteam.com/item.asp?ItemID=2368 to get this:DECLARE @po varchar(100)select @PO = COALESCE(@po + ', ', '') + CAST(PO AS varchar(50))FROM tmpPickupswhere ref = '1101188'SELECT @po
Which works fine but I want to put it into an update statement that takes all the PO's for each reference id and puts it on one line. I was looking at making it a function but the one I have:create function dbo.FnUpdatePos(@ref varchar(20))returns varchar(8000)asbeginDECLARE @PO varchar(100)SELECT @PO = COALESCE(@PO + ',', '') + CAST(po AS varchar(50))FROM vwSKPOsWHERE ref = @refRETURN @POend
used in a stored procedure:UPDATE tmpPickupsSET tmpPickups.PO = dbo.FnUpdatePos(vwSKPOs.ref)FROM tmpPickups INNER JOIN dbo.vwSKPOs ON dbo.tmpPickups.ref = dbo.vwSKPOs.ref
doesn't work. I get one PO where there should be at lease 2 and the rest of the columns get set to null.Any help you could provide would be much appreciated.ThanksLaura