I'd like to manipulate variables into behaving like enums,
CREATE TABLE dbo.ActionType
(
ActionID INT,
Name NVARCHAR(30)
)
INSERT INTO dbo.ActionType
(ActionID, Name)
VALUES
(100, N'Product_Insert'),
(101, N'Product_Update'),
(102, N'Product_Delete')
DECLARE @ACTION_INSERT TINYINT,
@ACTION_UPDATE TINYINT,
@ACTION_DELETE TINYINT
SELECT @ACTION_INSERT = ActionID,
@ACTION_UPDATE = ??, -- how would I do this properly?
@ACTION_DELETE = ?? -- or is it possible?
FROM dbo.ActionType
WHERE Name LIKE 'Product_%'
-- Test result, which always returns null
SELECT @ACTION_INSERT, @ACTION_UPDATE, @ACTION_DELETE
I know I could use CURSOR, but is there a better approach to doing this without iteration?