Monthly Archives: May 2012

SQL Question 17

Problem USE Northwind Write an inline table UDF that takes a CategoryID and returns the CategoryName, ProductName, Count of orders and Sum of Orders for each product in that category Code USE Northwind GO IF OBJECT_ID('fnProductsbyCategory','FN') IS NOT NULL DROP FUNCTION fnProductsbyCategory GO CREATE FUNCTION fnProductsbyCategory(@Categoryid int) RETURNS TABLE AS RETURN ( SELECT CategoryName ,…
Read more

SQL Question 16

Problem USE Northwind Write a scalar userdefined function that will return either the first name or last name The function will accept two parameters, the full name, ie ‘Lew Cousineau’ and an indicator of whether the user wants to return the first or last name. Test the function with the contact name in the customer…
Read more

SQL Question 15

Problem USE Northwind Write a script that will display the last name and count of orders for employees over 60. Use an IF statement in your script to test whether an employee is over 60 and if so then print the information. Also use a While statement to loop through all employees Don’t hard code…
Read more

SQL Question 14

Problem USE Northwind Write a script that will loop through all categories of products and display the productname of the top selling product. (by dollar amount) Make sure your numbers display with $ and commas Don’t hard code your loop. In other words your program should work whether there are 8 categories or 10. Code…
Read more