1
Let’s say I have this block:
declare @teste int
declare teste_cur cursor
for
select campo1 from tabela
.....
while @@fetch_status = 0
begin
set @teste = 0
select @teste = campo1 from tabela where campo2 = condicao2
end
.....
If select returns nothing, the @test variable remains zero(0) or not?
Seeing the answers of the colleagues below, I decided by doing this IF
if @rx_num_novo is null or @rx_num_novo = ''
begin
--Aquifaço meu Update/Insert/Delete
end
No, it won’t be.
– Reginaldo Rigo
@Reginaldorigo, but how do I make an if with it then? I only get it if it’s greater than zero on Count? What’s next? Null?
– pnet
@pnet looks at my answer... You have two selects, one without condition and the other with. If there is at least one record in your table, the value of the variable will be the value of the most internal select result, otherwise it will be null.
– Oralista de Sistemas
For testing purposes: to know if SELECT returned line (and had @test checked), use @@rowcount
– José Diz
My answer select as asked in the question the variable returns null and my test works just like this in the answer. The select made by @Renan does not come back null, returns empty, but not null, which is why in the case of it the variable does not change.
– Reginaldo Rigo
@Reginaldorigo, I know, I had to mark only one. If the system allows to afford two, mark yours too.
– pnet
I wasn’t even referring to that. I hadn’t even noticed it. I was referring to the difference between the two cases.
– Reginaldo Rigo
@Reginaldorigo, it was not my intention either, just to answer. Your answer is very correct, tested and worked. Note that I tested null and empty to meet my requirement, not that I was wrong. I put Null and Empty(Empty) for convenience.
– pnet