Select from table then form whitespace separated string in stored procedure
I want to highlight about 4-5 rows from a table and then form a space separated row.
All of this must be done in a stored procedure (SQL Server 2005).
Is it possible?
Then I will use this separator string and store it in another table.
Update
SELECT *
FROM Users
WHERE userID < 10
      
        
        
        
      
    output:
john
jake
blah
sam
      
        
        
        
      
    So, put this on a space separated line:
'john jake blah sam'
and store this row in another row in the table.
All of this should be done in a stored procedure (if possible).
+1 
BestPractise 
source
to share
      
2 answers
      
        
        
        
      
    
DECLARE @firstnames varchar(max)
SELECT 
    @firstnames = COALESCE(@firstnames + ' ', '') + FirstName 
FROM 
    Users 
WHERE 
    UserId < 10
INSERT INTO OtherTable (OtherColumn) VALUES (@firstNames)
      
        
        
        
      
    
+3 
Ian Nelson 
source
to share
      I think something like this will work:
DECLARE @whatever varchar(max)  -- or varchar(1000) or whatever size
SET @whatever = ''
SELECT @whatever = @whatever + MyColumn + ' ' FROM MyTable
      
        
        
        
      
    
0 
Micky mcquade 
source
to share