473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Store procedure help

I am trying to loop through a string of ID's and check if the
productname for the ID is 'Chai' if so change it to 'Tea'. This is in
the northwind db - products table. call it exec sp_UpdateProduct
'1,2,3'
It does not work, any ideas - syntax, etc....

CREATE PROCEDURE dbo.sp_UpdateProduct

@IDs varchar(200)

AS

BEGIN

declare @sStr1 varchar(200)
declare @iStrLen1 int
declare @sParseElm1 char(2)
declare @sStatus varchar(200)
declare @count int

set @sStr1= @IDs
set @iStrLen1= len(@sStr1)
SET @count = 0
while charindex(',',@sStr1) <> 0
begin
select @sParseElm1 = substring(@sStr1,1,CHARINDEX(',',@sStr1 ) - 1)
set @sStatus = 'select productname from products where productid
='+@sParseElm1

if @sStatus = 'CHAI'
update products set productname = 'TEA'
else
update products set productname = 'CHAI'
set @sStr1 = substring(@sStr1, CHARINDEX(@sStr1,',') + 1, @iStrLen1)

end
end
GO
Jul 20 '05 #1
1 1637
Johnny (jo*****************@yahoo.com) writes:
I am trying to loop through a string of ID's and check if the
productname for the ID is 'Chai' if so change it to 'Tea'. This is in
the northwind db - products table. call it exec sp_UpdateProduct
'1,2,3'
It does not work, any ideas - syntax, etc....


First, do not use the sp_ prefix for your stored procedures. This prefix
is reserved for system procedures, and SQL Server will first look for
such a procedure in the master database.

For a standard function for unpacking a list of integers to a table that
you then can join with, go to
http://www.algonet.se/~sommar/arrays...st-of-integers.

For for the replacement, you might be interested in the built-in
function replace(). Look it up in Books Online.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4017
by: Jin | last post by:
Hello: I run one process that calls the following the store procedure and works fine. create PROCEDURE sp_GetHostSequenceNum AS BEGIN SELECT int_parameter_dbf + 1
3
1477
by: serge calderara | last post by:
Dear all, One simple question relative to store procedure withinh ASP code on a web page. Let say that I am calling a store procedure to execute from a server button click on my web page. That...
1
2346
by: TARUN | last post by:
Hello All I get stuck in one problem , Please help me and excuse me on the poor Knowledge in SQL Server Store procedure Q1...I want to return a string type value from store procedure , Is it...
6
2711
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
0
1845
by: rxding | last post by:
Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, ...
1
7850
by: eRTIS SQL | last post by:
hi, I want to use a stored procedure inside a stored procedure simulteanously changing the database. this is my base store procedure alter PROCEDURE create_file @dbname sysname AS declare...
11
4346
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
2
1449
by: kuchel | last post by:
Hi I am trying to run 4 - 5 store procedure in a strict order. I have created a SSIS package whereby I trying to execute store procedure in a orderly fashion. I have created constraints between...
0
1531
by: seep | last post by:
salam to everyone.. as a new bee in .net i m finding lot of difficulty. i want to get all records of a table from database via store procedure.but spending many days i dont know how can i do...
0
1911
by: ramuygl | last post by:
want to create store procedure that. want to send the table name as argument and retrive the data of that argument. and want to store data in temperary table using the insert query. HERE I AM...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.