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.
| 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 ONDeclare @rowcount intSELECT * FROM t_orphanProductsWHERE subsection <> '098'AND [section] <> '098'AND dept <> '098' Select @rowcount = @@rowcountIf @rowcount = 0print 'hello'ELSEprint '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 intSELECT * FROM t_orphanProductsWHERE subsection <> '098'AND [section] <> '098'AND dept <> '098'Select @rowcount = @@rowcount PRINT @rowcount If @rowcount = 0print 'hello'ELSEprint 'Orphan Products exist'[/code]Check the values of @RowCount which is getting printed...Chirag |
 |
|
|
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. |
 |
|
|
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 selectsomthing like this Declare @rowcount intSELECT * FROM t_orphanProductsWHERE subsection <> '098'AND [section] <> '098'AND dept <> '098'Select @rowcount = @@rowcountSelect @rowcount If @rowcount = 0Select 'hello'ELSESelect'Orphan Products exist' Chirag |
 |
|
|
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. |
 |
|
|
|
|
|