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 2000 Forums
 Transact-SQL (2000)
 Arithematic help

Author  Topic 

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-01 : 11:26:42
I need help adding Varchar to a number.

Here's what I got:

CREATE PROC SP_UPDATEQUOTE
@QouteID VARCHAR(20),
@ID int
AS
SELECT @ID = @QuoteID
UPDATE AutoNum
SET ID = @ID + 1
WHERE TABLE = 'QUOTE'

When I run this, it keeps saying that there's no @ID parameter. I had set that as integer and set it to be the same as Varchar, but keeps giving me error. Any idea?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-04-01 : 11:29:28
@ID isn't a parameter, it's just a variable that should be declared in your stored proc. And you should always explicitly CAST or CONVERT between datatypes.

CREATE PROC SP_UPDATEQUOTE
@QouteID VARCHAR(20)
AS
Declare @ID int
SET @ID = CONVERT(int, @QuoteID)

UPDATE AutoNum SET ID = @ID + 1
WHERE TABLE = 'QUOTE'

- Jeff
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-04-01 : 11:34:59
Thanks Jeff. I was confuse and didn't realize that I need to declare it.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-04-01 : 11:46:48
As a suggestion, why not declare the parameter @QouteID as an INT to begin with, since it has to be a valid inteter?

If there is some reason you have to do it this way, you should add some checking to the proc to verify the the parameter is really a valid integer.




CODO ERGO SUM
Go to Top of Page
   

- Advertisement -