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)
 RAISERROR and the message isend throguh

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-06-07 : 10:12:25
i am doing this, to write the the event log :

set @Msg='Number of Rows Deleted on is : ' +Cast (@@ROWCOUNT as varchar(10))
RAISERROR (@Msg ,50000,1)

the thing is that if i try in a Stored Procedure concat a string i recive "error near '+' " ,and the code is this :


RAISERROR ('Number of Rows Deleted on is : ' +Cast (@@ROWCOUNT as varchar(10))
,50000,1)


why i cant just do like the second code,but must do like the first 1?
thnaks in advance
peleg


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-07 : 11:08:01
raiserror doesn't allow a concatenation.
try

raiserror('Number of Rows Deleted on is : %d' ,50000,1, @@ROWCOUNT)

Not a good idea to use @@rowcount like this though.
add select @rowcount = @@rowcount
after your statement then use @rowcount in the raiserror.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-06-07 : 13:54:26
quote:
Not a good idea to use @@rowcount like this though.


what not?can u explain?

thnaks in advance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-06-07 : 15:39:09
@@ROWCOUNT (and all @@ system variables I think) are only valid for the previous execution. For example:
DECLARE @T TABLE (a INT)

INSERT @T
SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4

IF @@ROWCOUNT = 4
PRINT '4 and @@ROWCOUNT = ' + CAST(@@ROWCOUNT AS VARCHAR)
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-06-10 : 05:55:20
Lamprey i dont understand what you are saying in the example?
the result i get is :

quote:

(4 row(s) affected)
4 and @@ROWCOUNT = 0


which means the select statment reseted the result?

thnaks
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-11 : 09:17:02
Every statement resets @@rowcount so
IF @@ROWCOUNT = 4
will reset @@rowcount to 0 so that is the value you get in the select.
in particular yo can't tetst @@rowcount and @@error separately


so better to do
select @rowcount = @@rowcount, @error = @@error
if @rowcount = 4
.....
if @error <> 0
.....

(not so much of a problem with the error handling in v2005).
==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-06-14 : 05:47:05
grreat !:)

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page
   

- Advertisement -