uerobertson
Programmer
I need to do an INSERT where I SELECT, concatenate and INSERT all in one statement.
I've researched thread183-90896, and FAQ183-1067 but neither are exactly what I need. Would someone please be able to help me with the syntax?
This code works for one record at a time but uses too many statments:
It produces this correct output:
This code does not work:
It produces this incorrect output:
There are a few thousand records (unique ina_prod_ids) and from 0 and up tech_spec records that need to be concatenated.
I understand that the reason the second snippet of code isn't working is because the @String isn't concatenating to itself because the
is missing. So, how can I add it in? (Please don't say it's impossible).
Thanks,
Ursula
Win 2000 and SS 2000
I've researched thread183-90896, and FAQ183-1067 but neither are exactly what I need. Would someone please be able to help me with the syntax?
This code works for one record at a time but uses too many statments:
Code:
CREATE PROCEDURE dbo.insertProductDescriptions
(@inaProdID AS int,
@locale AS char(2),
@vendorVPN AS varchar(20))
AS
DECLARE @String varchar(8000)
SELECT @String = ''
SELECT @String = @String + ' ' + CAST([Model Text] AS varchar(255))
FROM INAAdmin.AISTXD04
WHERE [Code of Text] = 'MTD' AND [IIC Model-Number] = @vendorVPN
UPDATE prodDescTest
SET tech_spec =
CAST (@String AS text)
WHERE prodDescTest.ina_prod_id = @inaProdID
AND prodDescTest.locale = @locale
Code:
ina_prod_id: 278
locale: en
prod_desc: Hooded Sweatshirt
tech_spec: Kangaroo pocket;new etirel logo embroidery on left chest inside brushed 280gr/m2
Code:
CREATE PROCEDURE dbo.insertProductDescriptions
(@locale AS char(2))
AS
DECLARE @String varchar(8000)
SET @String = ''
INSERT INTO prodDescTest
SELECT DISTINCT p.ina_prod_id,
@locale,
a5.[Product Short Desc]+' '+ a5.[Product Short Desc2] AS prod_desc,
@String + ' ' + CAST(a4.[Model Text] AS varchar(255)) AS tech_spec
FROM product_style p
LEFT JOIN INAAdmin.AISMBD05 a5
ON p.vpn = CAST(LTRIM(a5.[IIC Model-Number]) AS varchar(20))
LEFT JOIN INAAdmin.AISTXD04 a4
ON p.vpn = CAST(LTRIM(a4.[IIC Model-Number]) AS varchar(20))
AND LTRIM(RTRIM(a4.[Code of Text])) LIKE 'MTD'
It produces this incorrect output:
Code:
ina_prod_id: 278
locale: en
prod_desc: Hooded Sweatshirt
tech_spec: Kangaroo pocket;
ina_prod_id: 278
locale: en
prod_desc: Hooded Sweatshirt
tech_spec: new etirel logo embroidery on left chest
ina_prod_id: 278
locale: en
prod_desc: Hooded Sweatshirt
tech_spec: inside brushed 280gr/m2
There are a few thousand records (unique ina_prod_ids) and from 0 and up tech_spec records that need to be concatenated.
I understand that the reason the second snippet of code isn't working is because the @String isn't concatenating to itself because the
Code:
SELECT @String = @String...
Thanks,
Ursula
Win 2000 and SS 2000