Home All Groups Group Topic Archive Search About

Returning records updated

Author
14 Jul 2006 7:31 PM
David
I want to return the # of records updated and I was thinking of using the
following SP.  Will this work on SQL 2000 or 2005?  Thanks

CREATE PROCEDURE [ms_updROProblemCount]
(@RecordID  [int]
  @Processed [int] output)
AS UPDATE [Marshall].[dbo].[RepairOrder]
SET  [Problems]  = (SELECT Count([RecordID]) FROM  [dbo].[RepairOrderNotes]
WHERE (RecordID = @RecordID) AND (ActivityType = 'Problem') AND (Complete =
0))
WHERE ( [RecordID] = @RecordID)
SELECT @Processed = @@ROWCOUNT

David

Author
14 Jul 2006 9:52 PM
Andrew J. Kelly
David,

Did you try it and get an error or just asking?  Yes this should work but I
have a few suggestions.

1.  Add SET NOCOUNT ON directly after the AS portion of the sp.
2.  If the table being updated is in the same database as the sp itself you
should drop the database name. Just use schema.object.
3.  For the COUNT() you need to understand the difference between specifying
a column or using a *. The column method will not count rows with NULL
values in that column where as a * will count all rows that match the WHERE
clause. In this case it probably does not matter since you are specifying
that column in the WHERE clause anyway but just FYI.
--
Andrew J. Kelly SQL MVP

Show quote
"David" <dlch***@lifetimeinc.com> wrote in message
news:uyvjDy3pGHA.1592@TK2MSFTNGP04.phx.gbl...
>I want to return the # of records updated and I was thinking of using the
>following SP.  Will this work on SQL 2000 or 2005?  Thanks
>
> CREATE PROCEDURE [ms_updROProblemCount]
> (@RecordID  [int]
>  @Processed [int] output)
> AS UPDATE [Marshall].[dbo].[RepairOrder]
> SET  [Problems]  = (SELECT Count([RecordID]) FROM
> [dbo].[RepairOrderNotes] WHERE (RecordID = @RecordID) AND (ActivityType =
> 'Problem') AND (Complete = 0))
> WHERE ( [RecordID] = @RecordID)
> SELECT @Processed = @@ROWCOUNT
>
> David
>

AddThis Social Bookmark Button