|
|
| Article |
fooclass
Junior Member

Articles: 4 Comments: 1
|
|
|
| Posted: Fri Jul 06, 2007 3:46 pm |
|
|
Some of the applications may need to update the database procedure with bulk records at one go.
Instead of doing a loop calling the stored procedure, an array value can be passed to the stored procedure and update the database. I use this procedure to insert or update database values.
| Code: | Create procedure usp_updaterecords (@ArrayInput varchar(8000)) as
BEGIN
SET NOCOUNT ON
DECLARE @Row varchar(10), @Position int
SET @ArrayInput = LTRIM(RTRIM(@ArrayInput))+ ','
SET @Position = CHARINDEX(',', @ArrayInput, 1)
IF REPLACE(@ArrayInput, ',', '') <> ''
BEGIN
WHILE @Position > 0
BEGIN
SET @Row = LTRIM(RTRIM(LEFT(@ArrayInput, @Position - 1)))
IF @Row <> ''
BEGIN
-- add your insert or update statement here
END
SET @ArrayInput = RIGHT(@ArrayInput, LEN(@ArrayInput) - @Position)
SET @Position = CHARINDEX(',', @ArrayInput, 1)
END
END
END
GO |
Input value should be separated with ‘,’ comma. This procedure splits the values and assigns it to @Row variable.
If you have a situation like this, I may be able to help you. Post your comments or suggestions here. |
|
|
| Comments |
| No comments were made for this article |
| |
|
All times are GMT
You cannot post articles in this chapter You cannot edit your articles in this chapter You cannot delete your articles in this chapter You cannot rate articles in this chapter
You cannot post comments in this chapter You cannot edit your comments in this chapter You cannot delete your comments in this chapter You cannot rate comments in this chapter
|
|