What's the proper way to use a variable in a procedure?
Whenever I try and initialize one, I'm getting an error that I'm not using the proper syntax. Because I can't initialize it, whenever I try and use it I'm getting a null result. The variable is to be used inside a case when statement that first uses a select to check if something exists. Then, instead of running the select over again, I'd like just to return the variable.
right now all I have is
case when EXISTS(select @variable := column where CONDITIONS) then
@variable
when EXISTS(select @variable := column where OTHERCONDITIONS)
END
And it's not working.
Any tips or idea how to use the variables?
Thanks
Whenever I try and initialize one, I'm getting an error that I'm not using the proper syntax. Because I can't initialize it, whenever I try and use it I'm getting a null result. The variable is to be used inside a case when statement that first uses a select to check if something exists. Then, instead of running the select over again, I'd like just to return the variable.
right now all I have is
case when EXISTS(select @variable := column where CONDITIONS) then
@variable
when EXISTS(select @variable := column where OTHERCONDITIONS)
END
And it's not working.
Any tips or idea how to use the variables?
Thanks