| 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 9Incorrect syntax near '@Sale_Price'.Msg 137, Level 15, State 2, Procedure GetProfit, Line 20Must 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)ASBEGIN -- 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_NumberENDGO |
|
|
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 9Incorrect syntax near '@Sale_Price'.Msg 137, Level 15, State 2, Procedure GetProfit, Line 20Must 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)ASBEGIN -- 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_NumberENDGO
Missed commas------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 nameCREATE 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)ASBEGIN -- 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_NumberENDGO[/quote]Missed commas------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/[/quote] |
 |
|
|
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 tablealso you dont need tablename in wherethis is enoughUpdate Customer_vehicle_Sales_bridgeset Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))where Vin_Number = @Vin_Number ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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_NumberHere is my new error???? Msg 4145, Level 15, State 1, Procedure GetProfit, Line 22An expression of non-boolean type specified in a context where a condition is expected, near 'Number'. |
 |
|
|
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_Numberif I take the from statement out it does this::Msg 2714, Level 16, State 3, Procedure GetProfit, Line 19There is already an object named 'GetProfit' in the database.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/[/quote] |
 |
|
|
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_Numberif I take the from statement out it does this::Msg 2714, Level 16, State 3, Procedure GetProfit, Line 19There is already an object named 'GetProfit' in the database.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
[/quote]you need to add this before createIF EXISTS(SELECT 1 FROM sys.sql_modules WHERE OBJECT_DEFINITION(object_id) = 'GetProfit') DROP PROCEDURE GetProfitGOCREATE 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)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;-- Insert statements for procedure hereUpdate Customer_vehicle_Sales_bridgeset Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))where Vin_Number = @Vin_NumberENDGO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-06 : 17:55:38
|
ah ...there was a typoIF EXISTS(SELECT 1 FROM sys.sql_modules WHERE OBJECT_DEFINITION OBJECT_NAME(object_id) = 'GetProfit') DROP PROCEDURE GetProfitGOCREATE 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)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;-- Insert statements for procedure hereUpdate Customer_vehicle_Sales_bridgeset Profit = (@Cost - @Sale_Price - (@Sale_Price * @Commission_Rate))where Vin_Number = @Vin_NumberENDGO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|