I'm trying to perform a simple IF
statement. I have a table named 'products' that has a column count
which is a current count of that specific product in stock. The count
column in the database is of data type INT
.
I can only get this to work if I statically assign the variable @count
. If I assign a select statement to @count
the script fails. Even though running the query alone will return a result.
Working query:
DECLARE @count INT
SET @count = 2
IF (@count > 1)
BEGIN
PRINT 'It works!'
END
Failing query:
DECLARE @count INT
SET @count = (SELECT TOP 1 count from products WHERE count > 1)
IF (@count > 1)
BEGIN
PRINT 'It works!'
END