I have a set of characters, all of which must match the characters in another set.
e.g. All characters in “RW” must exist in “RWCE”.
There’s probably an easier way, but here’s one solution.
- Create a CTE table of the string to test, converting a set of letters to rows.
- Return any rows of just the missing or failed characters
- If a row EXISTS we want to report the error.
DECLARE @vcNewPermissions VARCHAR(128) SELECT @vcNewPermissions = 'RW' -- IF OBJECT_ID('tempdb.dbo.[#IllegalPermissions]') IS NOT NULL DROP TABLE [#IllegalPermissions] -- ;WITH [mycte]([x]) AS ( SELECT SUBSTRING([a].[FindString], [v].[number] + 1, 1) FROM ( SELECT @vcNewPermissions AS [FindString] ) [a] JOIN [master].[dbo].[spt_values] [v] ON [v].[number] < LEN([a].[FindString]) WHERE [v].[type] = 'P' ) SELECT [x] INTO [#IllegalPermissions] FROM [mycte] WHERE CHARINDEX([x], 'RWCESVXT') = 0 IF EXISTS ( SELECT * FROM [#IllegalPermissions] ) RAISERROR('ERROR: permission not found',16,1)