Incorrect Syntax Near Declare

Good Day:

I am using SQL Server 2000.  I am trying to write a stored procedure that updates the ExtendedPrice column based on calculations, but I get an error that reads: Incorrect syntax at declare.  My stored procedure is as follows:

CREATE PROCEDURE spUpdQuoteExtendedPriceC
       @QuoteNumber       [nvarchar](8)
       DECLARE @ExtendedPrice Money
AS UPDATE QuoteImport
  SET  @ExtendedPrice =  Quantity * UnitPrice
  SET  @ExtendedPrice=@ExtendedPrice / 100
  SET  ExtendedPrice=@ExtendedPrice
         WHERE
      ( QuoteNumber = @QuoteNumber AND UOM='C')
GO

Any Suggestions?
Thank You,
Denise
DeniseGoodheartAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
the declare is AFTER the AS

CREATE PROCEDURE spUpdQuoteExtendedPriceC
       @QuoteNumber       [nvarchar](8)
AS 
DECLARE @ExtendedPrice Money 
UPDATE QuoteImport 
  SET  @ExtendedPrice =  Quantity * UnitPrice 
  SET  @ExtendedPrice=@ExtendedPrice / 100
  SET  ExtendedPrice=@ExtendedPrice
         WHERE 
      ( QuoteNumber = @QuoteNumber AND UOM='C')
GO

Open in new window

ErnariashCommented:

If you need the ExtendedPrice  as parameter see code: thanks
CREATE PROCEDURE spUpdQuoteExtendedPriceC 
@QuoteNumber [nvarchar](8), 
@ExtendedPrice Money 
AS 
  
UPDATE QuoteImport 
SET ExtendedPrice =Quantity * UnitPrice 
SET ExtendedPrice=@ExtendedPrice / 100 
SET ExtendedPrice=@ExtendedPrice 
WHERE 
( QuoteNumber = @QuoteNumber AND UOM='C') 
GO

Open in new window

Guy Hengel [angelIII / a3]Billing EngineerCommented:
more errors... simplify your code like this:
CREATE PROCEDURE spUpdQuoteExtendedPriceC
 @QuoteNumber       [nvarchar](8)
AS
UPDATE QuoteImport 
   SET ExtendedPrice =  (Quantity * UnitPrice ) / 100
 WHERE QuoteNumber = @QuoteNumber 
   AND UOM='C'
GO

Open in new window

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

ErnariashCommented:
Whe do you need @ExtendedPrice Money  as a variable or parameter?
CREATE PROCEDURE spUpdQuoteExtendedPriceC
       @QuoteNumber       [nvarchar](8)
AS
UPDATE QuoteImport 
	  SET  ExtendedPrice=(Quantity * UnitPrice) / 100
WHERE   ( QuoteNumber = @QuoteNumber AND UOM='C')

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ErnariashCommented:

If you really need @ExtendedPrice as variable or parameter this could be the syntax. You only can have one SET with the Update:
Here you have some different  samples how to set variables :)

CREATE PROCEDURE spUpdQuoteExtendedPriceC
       @QuoteNumber   [nvarchar](8)
AS 
  DECLARE @ExtendedPrice Money 
  
----You will get the Price and Quantity / UnitPrice  from dif tables&
  SELECT TOP 1 @ExtendedPrice =  Quantity * UnitPrice  FROM PriceTable  WHERE QuoteNumber =@QuoteNumber
  
  SET  @ExtendedPrice=@ExtendedPrice / 100
    
  UPDATE QuoteImport 
  SET  ExtendedPrice=@ExtendedPrice
  WHERE  ( QuoteNumber = @QuoteNumber AND UOM='C')

Open in new window

mironCommented:
almost a copy of  Ernariash and Angel code

-- cheers
CREATE PROCEDURE spUpdQuoteExtendedPriceC
       @QuoteNumber nvarchar(8)
AS
UPDATE QuoteImport 
    SET  ExtendedPrice=(Quantity * UnitPrice) / CAST( 100 as money )
WHERE   ( QuoteNumber = @QuoteNumber AND UOM='C')

Open in new window

DeniseGoodheartAuthor Commented:
All three of you gave great examples.

Many thanks!

Cheers.
Denise

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.