I am relatively very new to SQL queries but I have this stored procedure where I am trying to get value of a declared variable as mentioned below but getting error,
First line is 20 here,
declare @m_ID_v int set @m_ID_v = ( select ID_C from M_T where MName_C = @MName_parameter) declare @g bit if (select G_L_Column from G_L_table Where M_ID_Column = @M_ID_variable) set @g_v = 1 else set @g_variable = 0 Exception I get:
Msg 4145, Level 15, State 1, Procedure GetID, Line 20
An expression of non-boolean type specified in a context where a condition is expected, near 'set'. Msg 156, Level 15, State 1, Procedure GetID, Line 21 Incorrect syntax near the keyword 'else'.
Now if I remove declare @g... and try to parse it, no error occurs
EDIT
I want my code to check for returned value by my select statement so "if exists" is not really what am looking for, sorry.
@gbut the assignment goes to a variable called@g_vor@g_variable.....IF ((SELECT x FROM y WHERE z = @v) = @testVariable)? At present you get backG_L_Column, but you don't say what you want to check it against. Also, isM_ID_Columnunique, allowing you to guarantee that your query only ever returns one row?