Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi All,Below is my scriptDECLARE @USERID VARCHAR(MAX)SET @USERID = ''SELECT @USERID = @USERID + CAST(USERID AS VARCHAR(10))+CAST(ISNULL(GROUP1NAME,'') AS VARCHAR(10))+',' FROM USERGROUPS1SELECT @USERIDThe USERGROUPS1 table consists 65000 rows, I need to concate all the userid and group1name column into single string.The above query take more that 15 minutes to complete.please suggest me to execute it in faster way.Solutions are easy. Understanding the problem, now, that's the hard part
Sachin.Nand
2937 Posts
Posted - 2011-07-29 : 03:21:19
Try this
DECLARE @USERID VARCHAR(MAX)Select @USERID=REPLACE(USERID ,' ',',') from(Select (Select convert(varchar(10),USERID) + '' + ISNULL(GROUP1NAME,'') FROM USERGROUPS1 for xml path(''))USERID )TSelect @USERID