You are missing the condition inside the sub query.
SELECT t2.Id, STUFF((SELECT ',' + CAST(VALUE AS varchar) FROM @MyTable t1 where t1.Id =t2.ID FOR XML PATH('')), 1 ,1, '') AS ValueList
FROM @MyTable t2
GROUP BY t2.Id
More Related Contents:
- Turning a Comma Separated string into individual rows
- How to split a comma-separated value to columns
- How to export data as CSV format from SQL Server using sqlcmd?
- The order of a SQL Select statement without Order By clause
- Select columns from result set of stored procedure
- SQL Server: SELECT only the rows with MAX(DATE)
- Import Multiple CSV Files to SQL Server from a Folder
- Bulk Insert Partially Quoted CSV File in SQL Server
- SQL Server Bulk insert of CSV file with inconsistent quotes
- Export table to file with column headers (column names) using the bcp utility and SQL Server 2008
- How can I import an Excel file into SQL Server? [closed]
- What does “ORDER BY (SELECT NULL)” mean?
- Taking the second last row with only one select in SQL Server?
- How to get the last row from a table in SQL Server?
- Storing a file in a database as opposed to the file system?
- Preferred Method of Storing Passwords In Database
- How do you count the number of occurrences of a certain substring in a SQL varchar?
- Why is it considered bad practice to use cursors in SQL Server?
- Import Excel spreadsheet columns into SQL Server database
- Hitting the 2100 parameter limit (SQL Server) when using Contains()
- How do I search an SQL Server database for a string?
- Fastest way to determine if record exists
- WHERE clause on SQL Server “Text” data type
- SQL Server – parameter sniffing
- Does the order of columns in a WHERE clause matter?
- SQL Rows to Columns
- What is the best way to implement Polymorphic Association in SQL Server?
- Set option 9 in SQL Server stored procedure using WinHttp.WinHttpRequest.5.1 for TLS 1.2
- How to generate auto increment field in select query
- How to maintain the order of insertion in SQL Server