我有以下是與下面的值返回一個變量@colsrate代碼:如何將動態變量值拆分爲單個列?
'[5.00],[5.00],[1.00],[35.00],[1.00],[1.00],[1.00],[1.00],[1.00],[1.00]'
我需要這個單獨的值轉換爲單個列。我怎樣才能做到這一點?謝謝。
SELECT
CAST((CAST(Rate AS DECIMAL(18,2))) AS NVARCHAR(255))AS Rate
,LEFT((CAST(StartDate AS NVARCHAR(255))), 11) AS StartDate
INTO #TempTab
FROM RepoCost.vwCurrencyRate
WHERE
CurrencyNameFrom = @CurrencyNameFrom
AND
[email protected]
AND
DimdateId= @DimdateId
SET @colsrate = STUFF((SELECT ','+QUOTENAME(Rate)
FROM #TempTab
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
添加預期輸出 –
預期輸出:選擇 '[5.00]', '[5.00]',「[ 1.00]','[35.00]','[1.00]','[1.00]','[1.00]','[1.00]','[1.00]','[1.00]' –