拥有值为
的表格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>'
答案 0 :(得分:2)
试试这个
DECLARE @val NVARCHAR(4000)
SELECT @val = COALESCE(@val + '', '') + refl
FROM #tbl
SELECT @val
答案 1 :(得分:0)
使用T-SQL split function,然后说
WHERE refl in IN yourSplitFunction(@val)