I want to get a list of comma separated customer names. The below code only returns the last name
DECLARE @vfirstname NVARCHAR(500), @vdelimiter NVARCHAR(1)
SET @vdelimiter=','
SELECT @vfirstname = FirstName + @vdelimiter
FROM dbo.Customer c
SET @vfirstname = LEFT(@vfirstname, LEN( @vfirstname ) - 1);
PRINT @vfirstname
I was able to fix it introducing the below statements (with help from google):
SET @vfirstname =''
SELECT @vfirstname = @vfirstname + FirstName + @vdelimiter
FROM dbo.Customer c
But I am unable to understand the need to do this , how does the select statement really work in this scenario?