Syntax error converting the varchar value 'admi' to a column of datatype int.

F

Franck

hello,
I have a pb with a stored procedure:
simple one:
CREATE PROCEDURE dbo.loginRoles(@Role varChar (60) output,
@UserId varChar (60) )
as
declare @nbreRow int
begin
set @nbreRow = (select count(*)
FROM [Northwind].[dbo].[EmailId]
where [UserId]=@UserId)
if ( @nbreRow>0 )
begin
set @Role = ----------------------
(select [roles ]
FROM [Northwind].[dbo].[EmailId]
where [UserId]=@UserId)
end
else
begin
set @Role ='generic' ----------------------
end
return @Role
end

If I assign the value in this statement: set @Role ='generic'
or if it does enter the condition the same message appear


System.Data.SqlClient.SqlException: Syntax error converting the varchar
value 'admi' to a column of data type int.

any ideas ?
thanks
 
L

Lale Divringi [MSFT]

You can only return 'int' types from your stored procedure. Since @Role is
not of type int, it is causing the error.

You already have @Role declared as an output parameter and have set its
value. Therefore you don't need the "return @Role" statement in your stored
procedure. Just remove that line and everything should work.


DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights.
 
F

Franck

Thanks a lot
it solved my pb! :)
You can only return 'int' types from your stored procedure. Since @Role is
not of type int, it is causing the error.

You already have @Role declared as an output parameter and have set its
value. Therefore you don't need the "return @Role" statement in your stored
procedure. Just remove that line and everything should work.


DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights.


Franck said:
hello,
I have a pb with a stored procedure:
simple one:
CREATE PROCEDURE dbo.loginRoles(@Role varChar (60) output,
@UserId varChar (60) )
as
declare @nbreRow int
begin
set @nbreRow = (select count(*)
FROM [Northwind].[dbo].[EmailId]
where [UserId]=@UserId)
if ( @nbreRow>0 )
begin
set @Role = ----------------------
(select [roles ]
FROM [Northwind].[dbo].[EmailId]
where [UserId]=@UserId)
end
else
begin
set @Role ='generic' ----------------------
end
return @Role
end

If I assign the value in this statement: set @Role ='generic'
or if it does enter the condition the same message appear


System.Data.SqlClient.SqlException: Syntax error converting the varchar
value 'admi' to a column of data type int.

any ideas ?
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top