4
I’m looking for an alternative to using the command Exists
in procedures I need to perform a large query and check if it returns any data, if it does not return the search should return a select with all its columns with the value '...'
.
Like I’m doing at the moment:
IF EXISTS(SELECT ..... FROM ..... WHERE .....) --Consulta muito grande, por isso não escrive ela.
BEGIN
SELECT ..... FROM ..... WHERE .....
END
ELSE
BEGIN
SELECT '...' as 'Col1', ....
END
The problem with this approach is that I need to run the query twice, causing a certain slowness in the process.
I implemented the use of
@@ROWCOUNT
and achieved the expected result! I would just like to ask you to add one more thing to the answer before I accept it: @@ROWCOUNT works only if stored Procedure does not have the commandSET NOCOUNT ON;
at the beginning of the same, I had this problem during the implementation.– Marciano.Andrade
@Marciano.Andrade Legal, good observation, already edited the answer.
– utluiz