Can anyone exaplin me this insert statement

  • Hi,

    INSERT INTO

    Fireball_RawImportData.dbo.MultiSourceWorkQueueBond

    (

    GenericKey,

    NewEntity

    )

    VALUES

    (

    dbo.GetGlobalUniqueEntityIdentifier('Fireball.dbo.Bond', CONVERT(INT, @SourceId)),

    0

    )

    What exactly is this insert doing I'm confused?

    ALTER FUNCTION [dbo].[GetGlobalUniqueEntityIdentifier]

    (

    @TableName VARCHAR(500),

    @NativeUniqueIdentifier VARCHAR(500)

    )

    RETURNS VARBINARY(20) AS

    BEGIN

    DECLARE @PersistenceSourceId UNIQUEIDENTIFIER = dbo.GetConfigurationValue_GUID('Fireball', 'Fireball Persistence Source')

    DECLARE @EntityType UNIQUEIDENTIFIER =

    (

    SELECT

    Class.EntityType

    FROM

    dbo.MultiSourceTableClassMap TableClass

    INNER JOIN

    Fireball_MetaData.dbo.Class ON

    Class.ClassId = TableClass.ClassId

    WHERE

    TableClass.TableName = @TableName

    )

    RETURN HASHBYTES(

    'SHA1',

    CAST(@PersistenceSourceId AS VARBINARY) +

    CAST(@EntityType AS VARBINARY) +

    CAST(@NativeUniqueIdentifier AS VARBINARY))

    END

  • What’s confusing in it? The INSERT statement is calling a function that returns hash bytes (varbinary value). :Whistling:

  • The functions looks like its meant to create a new unique value based on the input table name and the value returned from another function call within it. The output which is a hash value i.e var binary format is then inserted as it into the table.

    It seems the function is meant to do some sort of versioning based on the input data.

    Jayanth Kurup[/url]

  • varbinary value yes... but i'm getting null value i dont know why πŸ™

  • ashuthinks (1/2/2012)


    varbinary value yes... but i'm getting null value i dont know why πŸ™

    What value are you using for @SourceID?

    What do you get when you run this query?

    SELECT

    Class.EntityType

    FROM

    dbo.MultiSourceTableClassMap TableClass

    INNER JOIN

    Fireball_MetaData.dbo.Class ON

    Class.ClassId = TableClass.ClassId

    WHERE

    TableClass.TableName = 'Fireball.dbo.Bond'


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • check the inputs being passed to the functions

    Jayanth Kurup[/url]

  • SELECT

    Class.EntityType

    FROM

    dbo.MultiSourceTableClassMap TableClass

    INNER JOIN

    Fireball_MetaData.dbo.Class ON

    Class.ClassId = TableClass.ClassId

    WHERE

    TableClass.TableName = 'Fireball.dbo.Bond'

    this query giving me output : 2026ADB1-83FA-484A-AC95-2136AD94E638

    I have taken @SourceId = 0 .

    I'm not sure from where it is coming this parameter.

  • ashuthinks (1/2/2012)


    varbinary value yes... but i'm getting null value i dont know why πŸ™

    It will / may return NULLs if any of following is NULL:

    @PersistenceSourceId

    @EntityType

    @NativeUniqueIdentifier

    RETURN HASHBYTES(

    'SHA1',

    CAST(@PersistenceSourceId AS VARBINARY) +

    CAST(@EntityType AS VARBINARY) +

    CAST(@NativeUniqueIdentifier AS VARBINARY))

  • What does this return?

    select dbo.GetConfigurationValue_GUID('Fireball', 'Fireball Persistence Source')


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • select dbo.GetConfigurationValue_GUID('Fireball', 'Fireball Persistence Source')

    this returns:

    5C72E9D7-90CB-462C-8D6F-F8AF4163A416

  • Seems ok so far:

    DECLARE @NativeUniqueIdentifier VARCHAR(500) = '0'

    DECLARE @PersistenceSourceId UNIQUEIDENTIFIER = '5C72E9D7-90CB-462C-8D6F-F8AF4163A416'

    DECLARE @EntityType UNIQUEIDENTIFIER = '2026ADB1-83FA-484A-AC95-2136AD94E638'

    DECLARE @ReturnValue VARBINARY(20)

    SELECT @ReturnValue = HASHBYTES(

    'SHA1',

    CAST(@PersistenceSourceId AS VARBINARY) +

    CAST(@EntityType AS VARBINARY) +

    CAST(@NativeUniqueIdentifier AS VARBINARY))

    SELECT @ReturnValue

    What does this return?

    select dbo.GetGlobalUniqueEntityIdentifier('Fireball.dbo.Bond', CONVERT(INT, '0')),


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • ashuthinks (1/2/2012)


    select dbo.GetConfigurationValue_GUID('Fireball', 'Fireball Persistence Source')

    this returns:

    5C72E9D7-90CB-462C-8D6F-F8AF4163A416

    Chris's New Question: πŸ˜€

    What does it return?

    SELECT dbo.GetGlobalUniqueEntityIdentifier('Fireball.dbo.Bond', CONVERT(INT, @SourceId))

  • ChrisM@home (1/2/2012)


    Seems ok so far:

    ...

    What does this return?

    select dbo.GetGlobalUniqueEntityIdentifier('Fireball.dbo.Bond', CONVERT(INT, '0')),

    Ooops. I missed by few minutes. πŸ˜€

  • Dev (1/2/2012)


    ChrisM@home (1/2/2012)


    Seems ok so far:

    ...

    What does this return?

    select dbo.GetGlobalUniqueEntityIdentifier('Fireball.dbo.Bond', CONVERT(INT, '0')),

    Ooops. I missed by few minutes. πŸ˜€

    Haha! Thinking along the same lines 😎


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply