CREATE PROC test_concat
AS
BEGIN
DECLARE @LastCode char(4),
@LastDesc VARCHAR(512)
SELECT PDBC_PFX, BSTX_SEQ_NO,CONVERT(VARCHAR(512),BSTX_TEXT) BSTX_TEXT
INTO #CMC_BSTX_SUM_TEXT
FROM CMC_BSTX_SUM_TEXT where PDBC_PFX IN ('0157','0158','1579')
ORDER BY PDBC_PFX, BSTX_SEQ_NO
SET @LastCode = '',
@LastDesc = ''
UPDATE #CMC_BSTX_SUM_TEXT
SET @LastDesc = CASE WHEN BSTX_SEQ_NO = 0
THEN BSTX_TEXT
ELSE @LastDesc + BSTX_TEXT END,
BSTX_TEXT = CASE WHEN BSTX_SEQ_NO = 0
THEN BSTX_TEXT
ELSE @LastDesc + BSTX_TEXT END
--SELECT PDBC_PFX, MAX(BSTX_TEXT)
-- FROM #CMC_BSTX_SUM_TEXT GROUP BY PDBC_PFX
Select * from #CMC_BSTX_SUM_TEXT order by PDBC_PFX,BSTX_SEQ_NO
END
|