Please PLEASE avoid references to system tables, in particular system tables in system databases. In fact, the selected answer above will probably not compile in the Visual Studio 2013 Database Project
Table variables are accurate, but recursion with CTE is the answer:
DECLARE @str VARCHAR(max) SET @str = 'QWERTY AnotherWord' WITH Split(stpos,endpos) AS( SELECT 1 AS stpos, 2 AS endpos UNION ALL SELECT endpos, endpos+1 FROM Split WHERE endpos <= LEN(@str) ) SELECT 'character' = SUBSTRING(@str,stpos,COALESCE(NULLIF(endpos,0),LEN(@str)+1)-stpos) ,'charindex' = stpos FROM Split
However, using the above code is to get a table full of letters representing different permissions for the user. This is not a way to do this. Create a table with an identifier, permission code, and description, then create a link table between the user table and the new permission table. it gives you the same abilities and does not force you to solve such stupid problems like this.
M. Kirk Jennings
source share