Re: stored procedure question

From: MGFoster (me_at_privacy.com)
Date: 02/03/05


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


Relevant Pages

  • RE: Function and Stored procedure Problem
    ... > the type for login is nvarchar. ... > declare @IndexStart int ...
    (microsoft.public.sqlserver.programming)
  • stored procedure question
    ... I pass a stored procedure 2 strings: ... but it is looking for StringVal to be an INT ... @StringVal1 nvarchar, ...
    (microsoft.public.sqlserver.programming)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... where Bstrlib fails to be able to deal with them due to its design ... If the DOS port hadn't been dropped then depending on the compiler we ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... If the DOS port hadn't been dropped then depending on the compiler we ... And how do you deal with the fact that the language limits your sizes ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... Handling an RTF document that you will be writing to a variable length ... the scalar fields. ...
    (comp.lang.c)