1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
SELECT 'Average' = AVG(quantity) ,'Average #2' = AVG(CAST(quantity as decimal(5,2))) ,'Number' = COUNT(*) ,'Maximum' = MAX(quantity) ,'Minimum' = MIN(quantity) ,'Total' = SUM(quantity) FROM Orderlines; SELECT OrderDate ,'Payment due' = DATEADD(m,1,OrderDate) ,'Days ago' = DATEDIFF(dd,OrderDate,GETDATE()) ,'Today' = GETDATE() FROM Orders; SELECT 'Left 3' = LEFT('ABCDE', 3) ,'Length' = LEN('ABCDE') ,'Lower case' = LOWER('Abcde') ,'No leading spaces' = (LTRIM(' ABCDE')) ,'Right 3' = RIGHT('ABCDE', 3) ,'No trailing spaces' = RTRIM('ABCDE ') ,'Upper case' = UPPER('Abcde'); --create function CREATE FUNCTION fnDoubler (@input INT) RETURNS INT AS BEGIN SET @input = @input * 2; RETURN @input END --call function SELECT '16 * 2 = ' = dbo.fndoubler(16); -- Create the Logging table CREATE TABLE [dbo].[Logging] ( LogTime smalldatetime , LogMessage varchar(1000)); |