sql - Set more than 1 value to variable from Select statement -
i'm trying set varchar variable :
declare @var nvarchar(40) set @var = (select name tmptable name ) i want variable store value : 'name1,name2,name3,...' returns error 1 in title: subquery returned more 1 value.
i use variable in paramter of on function
select * tmp2 [dbo].[myfunction](@var, default) param ..... i know can't put more value in variable.i need variable represent more 1 value split value ","
any regard in regards
you can using stuff , for xml:
declare @var nvarchar(40) set @var = ( select distinct stuff((select ',' + name tmptable xml path ('')), 1, 1, '') tmptable ) but, ideally, shouldn't storing comma separated values in varchar. using table-variable work better:
declare @var table ( name nvarchar (40) ) insert @var (name) select name tmptable
Comments
Post a Comment