Stored proc issue... Best parameter type to use?
From: Alexis M (nospam_at_hotmail.com)
Date: 02/20/04
- Next message: Jacco Schalkwijk: "Re: SQL 6.5=>2000 Upgrade: ?Lint like tool for identifying potentially problematic"
- Previous message: David Portas: "Re: How to findout Eliminated record by when use Distinct function"
- Next in thread: Partha: "Stored proc issue... Best parameter type to use?"
- Reply: Partha: "Stored proc issue... Best parameter type to use?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 20 Feb 2004 14:11:27 GMT
Greetings,
I currently have a stored procedure that performs a user-selected operation
on a row, something like:
CREATE PROC sp_AlterRow
(
RowID INTEGER,
Operation INTEGER -- e.g. a number from 1 to 10 for the 10 valid
operations
Errors VARCHAR(255) OUTPUT
)
AS....
This returns 0 if successful, 1 otherwise. The stored proc is transactional,
i.e. a ROLLBACK is executed if any of the processing fails.
I now need to create a "parent" stored procedure to call this one and
perform the same operation on multiple rows. This will be an "all or none"
operation, i.e. if any of the calls fail, the entire process will be rolled
back. i.e.
CREATE PROC sp_AlterAllOrNone
(
<some parameter(s) indicating which rows to process>,
Operation INTEGER,
Errors VARCHAR(255) OUTPUT
)
AS
set @total = 0
BEGIN TRAN
For each <row> in <rows to process>
EXEC @result=sp_AlterRow <row>, Operation....
set @total=total+@result
next
IF @total<>0 ROLLBACK TRAN
Or something like that... my question is, how is it best to define which
rows to perform the operation on? I considered using a VARCHAR value to
store the RowIDs as delimited text, and split these into separate values.
however this can introduce errors and unpredictable behaviour, as this
"parent" procedure will be called by a number of clients (some developed in
.NET, other stored procedures, etc).
Another way I thought of was to have a table which the client would insert
rows into (two columns: <RowID>, <BatchNo>) and the parent stored proc will
be called with the "batch no" of which rows to process. However this adds
extra complexity to the client-side development.
I'd be extremely greatful for any other ideas you ladies and gentlemen may
have for me!
Thanks,
Alexis
< a l e x _ m 7 4 at h o t m a i l dot c o m >
--
- Next message: Jacco Schalkwijk: "Re: SQL 6.5=>2000 Upgrade: ?Lint like tool for identifying potentially problematic"
- Previous message: David Portas: "Re: How to findout Eliminated record by when use Distinct function"
- Next in thread: Partha: "Stored proc issue... Best parameter type to use?"
- Reply: Partha: "Stored proc issue... Best parameter type to use?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|