Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 @@rowcount concern !

Author  Topic 

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2006-08-23 : 08:24:02
Hi guys I know I have asked something similar to this before but I have searched and can't find it, so sorry for asking again

My code is as follows :

SET NOCOUNT ON
Declare @rowcount int

SELECT * FROM t_orphanProducts
WHERE subsection <> '098'
AND [section] <> '098'
AND dept <> '098'
Select @rowcount = @@rowcount


If @rowcount = 0
print 'hello'
ELSE
print 'Orphan Products exist'

The select statement above returns no rows but I still can't get my hello to print, why is this please ?

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-23 : 08:38:38
[code]
Declare @rowcount int

SELECT * FROM t_orphanProducts
WHERE subsection <> '098'
AND [section] <> '098'
AND dept <> '098'
Select @rowcount = @@rowcount

PRINT @rowcount
If @rowcount = 0
print 'hello'
ELSE
print 'Orphan Products exist'
[/code]

Check the values of @RowCount which is getting printed...
Chirag
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2006-08-23 : 08:44:14
Cheers Chirag nothing is getting printed for this print statemnt the only thing that is getting output is the empty cols from the t_orphanproducts table.
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-23 : 08:53:08
check in the message part of the Query analyser.

At the bottom of the query analyser you will be able to see the message click there and see what is,
printed.

other option is to use select

somthing like this


Declare @rowcount int

SELECT * FROM t_orphanProducts
WHERE subsection <> '098'
AND [section] <> '098'
AND dept <> '098'
Select @rowcount = @@rowcount

Select @rowcount
If @rowcount = 0
Select 'hello'
ELSE
Select'Orphan Products exist'


Chirag
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2006-08-23 : 09:12:36
Thanks Chirag the select answer you gave was the response I got before but I didnt realise that my initial code was viewable in the messages tab and that has the same effect, thank you for enlightening me.
Go to Top of Page
   

- Advertisement -