2013-11-25 36 views
0

與價值觀如何插入行重視

CREATE TABLE #tbl 
    (
     id int identity(1,1), 
     object_type int , 
     object_id nvarchar(50), 
     refl nvarchar(4000) 
    ) 

REFL值有這樣參數應用表:

<prov><CProv><object_type>1</object_type><object_id>152</object_id></CProv></prov> 
<prov><CProv><object_type>0</object_type><object_id>150</object_id></CProv></prov> 
<prov><CProv><object_type>0</object_type><object_id>156</object_id></CProv></prov> 
<prov><CProv><object_type>1</object_type><object_id>172</object_id></CProv></prov> 

我想選擇所有的數據至極是REFL另一個值declare @val nvarchar(4000)。 這可能嗎?當我嘗試select @val = refl from #tbl它只選擇最後一行,我想選擇所有行。它怎麼樣?它必須像

@val = N'<prov><CProv><object_type>1</object_type><object_id>152</object_id></CProv></prov> 
    <prov><CProv><object_type>0</object_type><object_id>150</object_id></CProv></prov> 
    <prov><CProv><object_type>0</object_type><object_id>156</object_id></CProv></prov> 
    <prov><CProv><object_type>1</object_type><object_id>172</object_id></CProv></prov>' 
+1

你的意思是說有4分排在#tbl表? – DarkKnight

+0

@HardCoreProgrammer是有4行 – GeoVIP

回答

2

試試這個

DECLARE @val NVARCHAR(4000) 
SELECT @val = COALESCE(@val + '', '') + refl 
FROM #tbl 

SELECT @val 
+0

非常感謝您節省我的時間 – GeoVIP

0

使用T-SQL split function,然後說

WHERE refl in IN yourSplitFunction(@val)