Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how do i return a varchar value

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-09-16 : 11:26:56
Hello,
I have a SP that returns a variable of varchar(30)

as

set @password = 'wait'
return @password

I get this error below.

Why ?

Msg 245, Level 16, State 1, Procedure mybilling, Line 107
Conversion failed when converting the varchar value 'wait' to data type int.





_____________________


Yes O !

jordanam
Yak Posting Veteran

62 Posts

Posted - 2008-09-16 : 11:34:55
Do you get the error compiling the proc or running it?

If it's a compile error, then my guess (and seeing the code would identify this quickly) is that you are performing a calculation using the variable or that there is a typo. If it's a run error, then it depends on how you're calling the sproc.

Posting code would help.

-------------

if your code was posted in this post: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=110730

then you are trying to set the password variable to a number (charindex is a numeric value). You can cast/convert that.

On charindex from BOL:
http://msdn.microsoft.com/en-us/library/ms186323.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-16 : 11:51:23
quote:
Originally posted by mary_itohan

Hello,
I have a SP that returns a variable of varchar(30)

as

set @password = 'wait'
return @password

I get this error below.

Why ?

Msg 245, Level 16, State 1, Procedure mybilling, Line 107
Conversion failed when converting the varchar value 'wait' to data type int.





_____________________


Yes O !


whats the datatype of @password?Also if you're doing this in udf whats the return type of udf?
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2008-09-16 : 13:04:18
declare @password varchar(30)
set @password = 'wait'
return @password

_____________________


Yes O !
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-09-16 : 14:23:15
Use a output variable

Create proc GetMyVal
@Password varchar(30) output
as
Select @Password = 'wait'
go

declare @PW varchar(30)
exec GetMyVal @Password = @PW output
select @PW
go
drop proc GetMyVal



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page
   

- Advertisement -