Have table @tbl
with INT
data :
ID
1
2
3
4
5
want select this id-s and set to declare @myStr nvarchar(max)
with " | "
It must be like : 1|2|3|4|5|
how to do it ?
Have table @tbl
with INT
data :
ID
1
2
3
4
5
want select this id-s and set to declare @myStr nvarchar(max)
with " | "
It must be like : 1|2|3|4|5|
how to do it ?
Use following Query:
declare @myStr nvarchar(max)
set @myStr=(SELECT STUFF((
SELECT '|' + CONVERT(VARCHAR,ID)
FROM @tbl
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, ''))
SELECT @myStr