Re: stored procedure question
From: MGFoster (me_at_privacy.com)
Date: 02/03/05
- Next message: Anith Sen: "Re: Please help with sorting?"
- Previous message: JJ Wang: "Re: URGENT: distribution agent failure: NT AUTHORITY\ANONYMOUS LOGON"
- In reply to: DaveF: "stored procedure question"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 03 Feb 2005 02:52:10 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Just convert the @NextString & @NextString1 to INTs:
UPDATE vote WITH (ROWLOCK)
SET no_votes = no_votes + 1
WHERE answer = CAST(@NextString1 TO INTEGER)
AND poll_id = CAST(@NextString TO INTEGER)
Assmues columns answer and poll_id are both INTEGERS. If they are some
other numeric data type, put that data type indicator in the CAST()
function.
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA) -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBQgGR0YechKqOuFEgEQLx3wCgu71Nw9ozIc+rxLm1oVpyG1leyvgAoO1t Qgr0n1bZTazkYSWfDCxWnSMQ =on+O -----END PGP SIGNATURE----- DaveF wrote: > I pass a stored procedure 2 strings: > > '1,11,21' StringVal > and > > '1,2,3' StringVal1 > > need to loop threw the values and update the table? This is what I am > trying, but it is looking for StringVal to be an INT > > ALTER PROCEDURE dbo.updateVotes > ( > @StringVal nvarchar (50), > @StringVal1 nvarchar (50), > @DelimiterVal nvarchar (10), > @NameVal nvarchar (50), > @EmailVal nvarchar (50) > ) > as > > begin > declare @NextString nvarchar(50) > declare @NextString1 nvarchar(50) > declare @Pos int > declare @NextPos int > declare @CountItems int > > > --Initialize > set @NextString = '' > > > set @StringVal = @StringVal + @DelimiterVal > > --Get position of first Comma > set @Pos = charindex(@DelimiterVal,@StringVal) > set @NextPos = 1 > > --Loop while there is still a comma in the String of levels > while (@pos <> 0) > begin > set @NextString = substring(@StringVal,1,@Pos - 1) > set @NextString1 = substring(@StringVal1,1,@Pos - 1) > > UPDATE vote WITH (ROWLOCK) SET no_votes = no_votes + 1 WHERE (answer > =ltrim( rtrim(@NextString1))) AND (poll_id = @NextString) > > set @StringVal = substring(@StringVal,@pos +1,len(@StringVal)) > set @StringVal1 = substring(@StringVal1,@pos +1,len(@StringVal1)) > > set @NextPos = @Pos > set @pos = charindex(@DelimiterVal,@StringVal) > end > > return > end
- Next message: Anith Sen: "Re: Please help with sorting?"
- Previous message: JJ Wang: "Re: URGENT: distribution agent failure: NT AUTHORITY\ANONYMOUS LOGON"
- In reply to: DaveF: "stored procedure question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|