No Orders: Find Missing Values Tempdb
No Orders: Find Missing Values Tempdb
create table T1
(
keycol int not null primary key,
datacol varchar(10) not null
);
--insert into T1(keycol,datacol)values(1,'e');
insert into T1(keycol,datacol)values(2,'f');
insert into T1(keycol,datacol)values(3,'a');
insert into T1(keycol,datacol)values(4,'b');
insert into T1(keycol,datacol)values(6,'c');
insert into T1(keycol,datacol)values(7,'d');
Return all employees with managers they report to
Return customer company name and supplier company name, where the
supplier supplies the products to the consumer
Returns customer company name and supplier company name , where the
supplier supplied the products to the customer.Also, return the
customers that made no orders
Select for each year, the sliding total of the previous year’s orders
Select Country and num cities covered by customers and employee
Return orders places by customer ‘alfki’ also orders handled by
employee 3
Create View using CTE
Create function using CTE
Select 3 most recent orders
select most recent 1 percent orders
select first 3 orders in order of increasing customerid
select @n most recent orders ,where @n is an argumento to Top
select average no of monthly orders from orders.
Select the two most expensive beverages(categoryid =1) for each
supplier
Select the two most expensive beverages(categoryid =1) for each
supplier using FUNCTION
Select suppliers who did not supply beverages
Select suppliers who did not supply beverages using FUNCTION.
Select lower of the two most expensive beverages(categoryid =1) for
each supplier
Select lower of the two most expensive beverages(categoryid =1) for
each supplier using FUNCTION
write a function named AddNumberDays that takes a date and an
integer, then it returns the date added to the number.
Write a function named GetNumberDays that takes 2 dates and returns
the number of days between them
Write a function named GetWeekDayName that when given a date, can
find and display the name of the week for the date.
Write a functinon named ProcessPayroll1 that takes the number of
hours worked in a week.Then the function returns a value that
represents overtime.If the employee worked less than 40 hours, there
is no overtime.If the employee worked for more than 40 hours, the
number over 40 is considered overtime.
Write a function to find the start and end dates of the week for the
passed date.
Write a function to get the days in a month
Write a function to determine whether the year is a leapyear
Write a function to calculate the days in a year
Write functin to calculate the time difference in hour
Write function to calculate the time difference in hour and min
Write a function to Get Last Day Of Month
Write function to get the first day of the quarter
Match each employee’s order with his previous order.
Match each employee’s order with his previous order using CTE
Select a random row from Orders table.(Using RANC() and
CHECKSUM(newid()))
Select the median of the val column for the whole table
Select the median of the val column for each group
******
if OBJECT_ID('dbo.groups') is not null
drop table dbo.groups;
go
Use Adventureworks
Calculate running total of each sale(This example calculates the
running total amount by summing up all the TotalDue amounts for
SalesOrderID's less then or equal to the current SalesOrderID).
Calculate a running subtotals for each OrderDate.( The subtotals are
calculated by summing the TotalDue by OrderId with where the Order
dates are the same)