SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am using a cursor and I am trying to check if the record exists and assign it to a variable at the same time , but for some reason it is erroring out. -Incorect sintaxsis near '='
IF EXISTS( SELECT TOP 1 @Event=[se.EventTest] FROM Test)
You cannot do variable assignment in IF EXISTS. You could do this:
SELECT @event = NULL
SELECT TOP 1 @event = "se.EventTest" FROM Test
IF @event IS NOT NULL
BEGIN
...
Note that you need to set the variable to NULL before the assignment, because if SELECT does not hit any rows, @event will retain it's value and will not be set to NULL.