I want to do something like this in T-SQL, but it will return an error:
DECLARE @Stock int
IF(SELECT @Stock = [Stock] FROM dbo.Products WHERE [ProductID] = 1) > 5
PRINT 'Stock is good: Current stock is ' + @Stock
ELSE
PRINT 'Order some more - we are below minimum stock'
The error returned is:
Msg 102, Level 15, State 1, Line 2: Incorrect syntax near '='.
I can of course do something like this instead:
DECLARE @Stock int
SELECT @Stock = [Stock] FROM dbo.Products WHERE [ProductID] = 1
IF(@Stock > 5)
PRINT 'Stock is good: Current stock is ' + @Stock
ELSE
PRINT 'Order some more - we are below minimum stock'
I am not sure if it is just the way the T-SQL language works and there is nothing to do about it. I am basically looking for a shortcut to write less code :)
Anybody has some good ideas?