I have this stored procedure, I was wondering if “if exists” will actually compare the value returned by select statement or it will just check if that condition can be executed or not, sorry for such a stupid question but I am new to SQL,
declare @m_ID_v int
set @m_ID_v = ( select ID_C from M_T where MName_C = @MName_parameter)
declare @g bit
if exists (select G_L_Column from G_L_table Where M_ID_Column = @M_ID_variable)
set @g_v = 1
else
set @g_variable = 0
my select statement
select G_L_Column from G_L_table Where M_ID_Column = @M_ID_variable
Is returning either true or false, so just wanna make sure if “if exists” will work as “if”
Using
if existsis not working asif. It doesn’t check if the returned value is true or false, it checks if there exists a value.If your query always returns a value, the
if existswill always evaluate to true.