Quantcast
Channel: issue with @@rowcount
Viewing all articles
Browse latest Browse all 6

issue with @@rowcount

$
0
0
why in both the occassion it is printing the same out put, could you plz tell me how to check this 

SELECT A FROM tab WHERE 1=1 then I want to print
'PERFORM OTHER ACTION'
SELECT A FROM tab WHERE 1=2 then I want to print
'no data found'


Actually I am trying to implement when_no_data found exception of oracle in to sqlserver, for me when no records is selected then no_data_found else preform other action..


CREATE TABLE tab ( A SMALLINT)
INSERT INTO tab VALUES(1)

DECLARE 
@A NUMERIC
BEGIN
   SELECT @A = (SELECT A FROM tab WHERE 1=1)
   IF @@ROWCOUNT = 0
   BEGIN 
    PRINT 'no data found'
   END
 PRINT 'PERFORM OTHER ACTION'
END
 
output--> PERFORM OTHER ACTION


DECLARE 
@A NUMERIC
BEGIN
   SELECT @A = (SELECT A FROM tab WHERE 1=2)
   IF @@ROWCOUNT = 0
   BEGIN 
    PRINT 'no data found'
   END
 PRINT 'PERFORM OTHER ACTION'
END
 
output--> PERFORM OTHER ACTION --the out put should be no_data_found

aak

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images