Jump to content

jones77622

Members
  • Posts

    22
  • Joined

  • Last visited

Posts posted by jones77622

  1. would this be the correct syntax??USE

    GO/****** Object:  UserDefinedFunction [dbo].[CalculateTotal]    Script Date: 11/21/2013 17:42:13 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[CalculateTotal]()RETURNS moneyASBEGIN    DECLARE @totalcost money;    SELECT @totalcost = (crustprice + Sideprice + Toppingprice)    FROM dbo.Crusttable, dbo.SidesTable, dbo.ToppingsTable, dbo.order1LEFT JOIN crusts AS c ON o.crust=c.crustIDLEFT JOIN toppings AS t ON o.toppings=t.toppingIDLEFT JOIN sides AS s ON o.sides=s.sideID    Return @totalcost    END 
  2. You need to have a join condition. That join is going to join every row in those tables. You want to join the records for a single record in the order1 table, so you need to tell it which record you're working with. That means the function needs a parameter that represents the row that you're trying to calculate the total for, and then the join needs to use that ID to get the data for that order.

     

    can you help me write the correct syntax for that join command thanks

  3. i made this function do you think this would work for me?

     

     

    USE

    GO/****** Object:  UserDefinedFunction [dbo].[CalculateTotal]    Script Date: 11/21/2013 17:42:13 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[CalculateTotal]()RETURNS moneyASBEGIN    DECLARE @totalcost money;    SELECT @totalcost = (crustprice + Sideprice + Toppingprice)    FROM dbo.Crusttable, dbo.SidesTable, dbo.ToppingsTable, dbo.order1    Return @totalcost    END
  4. Here is the transact code i cant seem to get it to work properly

     

     

     

    USE

    GO/****** Object:  Trigger [dbo].[Trigger1]    Script Date: 11/21/2013 10:31:57 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:        Name-- Create date:-- Description:    -- =============================================ALTER TRIGGER [dbo].[Trigger1]   ON  [dbo].[order1]   AFTER INSERT,UPDATEASBEGIN    -- SET NOCOUNT ON added to prevent extra result sets from    -- interfering with SELECT statements.    SET NOCOUNT ON;    -- Insert statements for trigger hereSELECT Crust, Toppings, Sides, Crustprice + ToppingPrice + SidePrice as TotalCost FROM order1, Crusttable, ToppingsTable, SidesTableEND 
  5. How do i get it to show up on the order table when i view it in select top 1000 rows on the order table ???

     

    It shows the proper price in the query but it does not show it on the ordertable query select top 1000 rows

     

    This is the query that worked so far

     

    SELECT OrderID, Crust, Toppings, Sides, Crustprice + ToppingPrice + SidePrice as OrderPrice FROM order1 AS o LEFT JOIN Crusttable AS c ON crust=crustID LEFT JOIN ToppingsTable AS t ON Toppings=toppingID LEFT JOIN sidestable AS s ON sides=sideID

  6. I have a database of 5 tables. 1st table is my customer table. 2nd is my crust table. 3rd is my toppings table. 4th is my sides table. 5th is my order table. My crust, toppings and sides table all have a price column and I am trying to get them to add together on my order table total cost column. What function would be the best to use to accomplish getting the crust price toppings price and sides price to add up on the order table Total cost column?

    Here is my table schema:

    Crust TableCrustID Primary KeyCrustnameCrustsizeCrustprice moneyToppings TableToppingID Primary KeyToppingNameToppingPrice moneySides TableSideID Primary KeySideNameSidePortionSidePrice moneyCustomer TableCustomerID Primary KeyFnameLnameStreetCityStateZipPhonenumberemailaddress Order TableOrderId Primary Key INTCustomer Foreign Key INTCrust Foreign Key INTToppings Foreign Key INT

    Sides foreign key int

    TotalCost money

×
×
  • Create New...