DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to apply scalar-valued function for restaurant specials?

Execute the following SQL Server T-SQL script in SSMS Query Editor to create a function for the automatic generation of daily specials:

USE AdventureWorks2008;

GO

-- T-SQL create user-defined scalar-valued function - UDF

CREATE FUNCTION fnRoadsideDinerDailySpecial( )

RETURNS NVARCHAR(50)

AS

  BEGIN

    DECLARE  @DailySpecial NVARCHAR(50),

             @DayOfWeek    CHAR(10)

    

    SET @DayOfWeek = UPPER(DateName(dw,getdate()))

    

    IF @DayOfWeek = 'MONDAY'

      SET @DailySpecial = 'Chicken breast a''la San Francisco'

    

    IF @DayOfWeek = 'TUESDAY'

      SET @DailySpecial = 'Hungarian beef goulash'

    

    IF @DayOfWeek = 'WEDNESDAY'

      SET @DailySpecial = 'Almond-crusted scrod with penne pasta'

    

    IF @DayOfWeek = 'THURSDAY'

      SET @DailySpecial = 'Hamburger with sauteed mushrooms and onions'

    

    IF @DayOfWeek = 'FRIDAY'

      SET @DailySpecial = 'Cajun shrimp New Orleans style'

    

    IF @DayOfWeek = 'SATURDAY'

        OR @DayOfWeek = 'SUNDAY'

      SET @DailySpecial = 'Sorry no special today'

    

    RETURN (@DailySpecial)

  END

GO

 

SELECT DailySpecial = dbo.fnRoadsideDinerDailySpecial()

GO

-- Cajun shrimp New Orleans style

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE