Home All Groups Group Topic Archive Search About

Conversion to int error

Author
14 Jul 2005 4:07 PM
quiglepops
Here is a code excerpt from a large proc I have inherited. It runs from
within an application, but when I take it outside and try to run it in Query
Analyzer I encounter problems... (Note that these are only code sections and
I have included all relevant lines)


DECLARE @Entity varchar(12)
DECLARE @Fundgroup varchar(12)
DECLARE @Fund_Grps char(12)

SELECT @Entity  = NULLIF( RTRIM( @Entity ) , '' ) (this part is earlier in
the proc where it appears to set all blank parameters to NULL, note that
entity is passed in as a parameter)
SELECT @Fundgroup = NULL

SELECT @Entity  = 'SLOCUS'

IF  @Entity IS NOT NULL
  SELECT @Fund_Grps = @Entity
ELSE
  SELECT @Fund_Grps = @Fundgroup

DECLARE @idx  int
SELECT  @idx = LEN(RTRIM( @Fund_Grps ))


If I do a len, rtrim on @fund_groups I get the value 6.

However when it gets to the SELECT @IDX statement is gives the following
error message

Server: Msg 245, Level 16, State 1, Line 86
Syntax error converting the varchar value 'SL' to a column of data type int.

Any idea's ?

Author
14 Jul 2005 4:24 PM
David Gugick
quiglepops wrote:
Show quote
> Here is a code excerpt from a large proc I have inherited. It runs
> from within an application, but when I take it outside and try to run
> it in Query Analyzer I encounter problems... (Note that these are
> only code sections and I have included all relevant lines)
>
>
> DECLARE @Entity varchar(12)
> DECLARE @Fundgroup varchar(12)
> DECLARE @Fund_Grps char(12)
>
> SELECT @Entity  = NULLIF( RTRIM( @Entity ) , '' ) (this part is
> earlier in the proc where it appears to set all blank parameters to
> NULL, note that entity is passed in as a parameter)
> SELECT @Fundgroup = NULL
>
> SELECT @Entity  = 'SLOCUS'
>
> IF  @Entity IS NOT NULL
>  SELECT @Fund_Grps = @Entity
> ELSE
>  SELECT @Fund_Grps = @Fundgroup
>
> DECLARE @idx  int
> SELECT  @idx = LEN(RTRIM( @Fund_Grps ))
>
>
> If I do a len, rtrim on @fund_groups I get the value 6.
>
> However when it gets to the SELECT @IDX statement is gives the
> following error message
>
> Server: Msg 245, Level 16, State 1, Line 86
> Syntax error converting the varchar value 'SL' to a column of data
> type int.
>
> Any idea's ?

There is no "@fund_groups" declared in the code you posted. The error
implies there is a varchar the with problem which means (according to
what you posted) it's either the @Entity or  @Fundgroup variables.




--
David Gugick
Quest Software
www.imceda.com
www.quest.com

AddThis Social Bookmark Button