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
 General SQL Server Forums
 New to SQL Server Programming
 stored procedure errors...

Author  Topic 

tazzy0429
Starting Member

5 Posts

Posted - 2012-05-06 : 16:44:56
I have to create a database for car sales with a stored procedure that uses a bridge table to use cost, sales price and commision to calculate the profit. i keep getting these errors :

Msg 102, Level 15, State 1, Procedure GetProfit, Line 9
Incorrect syntax near '@Sale_Price'.
Msg 137, Level 15, State 2, Procedure GetProfit, Line 20
Must declare the scalar variable "@Cost".

Can anyone tell me what I am doing wrong I have stared at this until it has had me going in circles.


CREATE PROCEDURE GetProfit
-- Add the parameters for the stored procedure here
@Cost numeric = 0
@Sale_Price numeric = 0
@Commision_Rate numeric = 0
@Vin_Number varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Customer_vehicle_Sales_bridge.Vin_Number = @Vin_Number


END
GO

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-06 : 16:51:40
quote:
Originally posted by tazzy0429

I have to create a database for car sales with a stored procedure that uses a bridge table to use cost, sales price and commision to calculate the profit. i keep getting these errors :

Msg 102, Level 15, State 1, Procedure GetProfit, Line 9
Incorrect syntax near '@Sale_Price'.
Msg 137, Level 15, State 2, Procedure GetProfit, Line 20
Must declare the scalar variable "@Cost".

Can anyone tell me what I am doing wrong I have stared at this until it has had me going in circles.


CREATE PROCEDURE GetProfit
-- Add the parameters for the stored procedure here
@Cost numeric = 0,
@Sale_Price numeric = 0 ,
@Commision_Rate numeric = 0,
@Vin_Number varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Customer_vehicle_Sales_bridge.Vin_Number = @Vin_Number


END
GO



Missed commas

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tazzy0429
Starting Member

5 Posts

Posted - 2012-05-06 : 17:04:33
OMG, IBoy do I feel Dumb. LOL! Thanks you so much!!! Now the only error I have is telling me that Vin_Number is an invalid column name


CREATE PROCEDURE GetProfit
-- Add the parameters for the stored procedure here
@Cost numeric = 0,
@Sale_Price numeric = 0 ,
@Commision_Rate numeric = 0,
@Vin_Number varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Customer_vehicle_Sales_bridge.Vin_Number = @Vin_Number


END
GO

[/quote]
Missed commas

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


[/quote]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-06 : 17:08:36
check if you've column present in Customer_vehicle_Sales_bridge table

also you dont need tablename in where

this is enough



Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Vin_Number = @Vin_Number



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tazzy0429
Starting Member

5 Posts

Posted - 2012-05-06 : 17:20:19
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * Commision_Rate))
from dbo.Vehicle, dbo.Sales_Person
where Vin Number = @Vin_Number

Here is my new error????

Msg 4145, Level 15, State 1, Procedure GetProfit, Line 22
An expression of non-boolean type specified in a context where a condition is expected, near 'Number'.
Go to Top of Page

tazzy0429
Starting Member

5 Posts

Posted - 2012-05-06 : 17:22:33

Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commision_Rate))
where Vin_Number = @Vin_Number

if I take the from statement out it does this::

Msg 2714, Level 16, State 3, Procedure GetProfit, Line 19
There is already an object named 'GetProfit' in the database.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


[/quote]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-06 : 17:33:13
quote:
Originally posted by tazzy0429


Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commision_Rate))
where Vin_Number = @Vin_Number

if I take the from statement out it does this::

Msg 2714, Level 16, State 3, Procedure GetProfit, Line 19
There is already an object named 'GetProfit' in the database.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




[/quote]
you need to add this before create


IF EXISTS(SELECT 1 FROM sys.sql_modules WHERE OBJECT_DEFINITION(object_id) = 'GetProfit')
DROP PROCEDURE GetProfit
GO

CREATE PROCEDURE GetProfit
-- Add the parameters for the stored procedure here
@Cost numeric = 0,
@Sale_Price numeric = 0 ,
@Commision_Rate numeric = 0,
@Vin_Number varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Vin_Number = @Vin_Number


END
GO


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tazzy0429
Starting Member

5 Posts

Posted - 2012-05-06 : 17:51:25
I added that statement and clicked execute and it still says the same thing maybe I should shutdown database and restart??? Then retry?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-06 : 17:55:38
ah ...there was a typo

IF EXISTS(SELECT 1 FROM sys.sql_modules WHERE OBJECT_DEFINITION OBJECT_NAME(object_id) = 'GetProfit')
DROP PROCEDURE GetProfit
GO

CREATE PROCEDURE GetProfit
-- Add the parameters for the stored procedure here
@Cost numeric = 0,
@Sale_Price numeric = 0 ,
@Commision_Rate numeric = 0,
@Vin_Number varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Update Customer_vehicle_Sales_bridge
set Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))
where Vin_Number = @Vin_Number


END
GO


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -