• rho_pooka (1/11/2014)


    Greetings! On chapter four looking at inline table valued functions. Can someone translate this code into English? I see this at the beginning of a lot of code posted in the forum, and now in the 70-461 book, but have a hard time deciphering it. I don't understand the 'IF' in the parentheses nor the "IS NOT NULL DROP"

    IF OBJECT_ID('HR.GetManagers', 'IF') IS NOT NULL DROP FUNCTION HR.GetManagers;

    GO

    CREATE FUNCTION HR.GetManagers(@empid AS INT) RETURNS TABLE

    AS

    RETURN

    .....--goes on to create CTE

    As I read it, it looks like:

    If HR.GetManagers, or IF (why if?) exists, delete them, and create a new HR.Getmanagers function that requires an input of @empid that is an INT. Once putting in the INT for @empid, the function will use it help create a CTE, then I can query the CTE. Is that close?

    First question, have you taken the time to look up the function OBJECT_ID in Books Online? Here is a link to the function OBJECT_ID: http://msdn.microsoft.com/en-us/library/foof89286db-440f-4218-a828-30881ce3077a.aspx

    The 'IF' in this function call referes to the type for inline function. The IF statement is determining if the function already exists in the current database and if it does to drop the function.

    The function is then created (or if dropped it is recreated).