Hi all-
So I am taking a "Data Management Concepts and Database Administration" class using Microsoft SQL and so far it has been great. This week, I hit a wall once we started creating functions probably because I took programming more than 20 years ago and do not have a database background. If you can help me with my homework (no it is not cheating because I am an adult paying a fortune for grad school) I would really appreciate it. I have read the class text, watched the videos, checked a few online resources including SQL Tutorial but am stuck and cannot make it work; I assume that I am missing something really simple in the syntax and/or order of using SELECT, WHERE, HAVING, Aggregate functions, and parameters.
If this is easier by email or phone, please PM me and I will send you my contact info.
We are using a simple relational DB:
VENDOR
- VendorID (PK)
- VendorName
PRODUCT
- ProductID (PK)
- ProductName
- ProductDescription
- QtyOnHand
VENDORPRODUCT
- VendorProductID (PK)
- Cost
- Product.ProductID (FK)
- Vendor.VendorID (FK)
Here is what I need to complete:
1) Code and execute the statement to create a function called PreferredVendor that accepts a product id parameter as an input and returns the Vendor ID of the Vendor with the lowest cost in VENDORPRODUCT.
2) Code and execute the select statement that returns the ProductName, ProductDescription, QtyOnHand, and the preferred VendorID (use your function).
For #1, I was trying to use a SELECT statement to get the VendorID and using a WHERE clause to filter by MIN(Cost) but could not make it work. Again, I think I am mixing up the use and syntax of the statements.
For #2, I thought I could use a SELECT and JOIN statement for ProductName, ProductDescription, QtyOnHand but since I cannot complete #1 I can't use my function in this answer.
Any help would be greatly appreciated.
Bookmarks