Table variables

  • Comments posted to this topic are about the item Table variables

    Igor Micev,My blog: www.igormicev.com

  • An easy one for the day!

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • Easy qstn to start the day.

    --
    Dineshbabu
    Desire to learn new things..

  • +1

  • Eeezy Peezy!! :-P:-D

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • Easy one, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This was removed by the editor as SPAM

  • Thanks for the question.

    Can I ask that they are all like this until the New Year?

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • Oof! That was a tough one, after using up my 50/50 I had to call a friend! Maybe it was a trick question.

    Alas no, a nice easy one for this morning, and very much appreciated.

    Good question thanks. 😀

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • In case anybody wonders, on a similar note...

    Can table valued parameters be used in a function?.

    .

    .

    .

    Yes!

    and they are very useful fo creating functions that take name-value-pairs

    e.g.

    CREATE TYPE [dbo].[AuditNVP] AS TABLE(

    [Name] [varchar](128) NULL,

    [Value] [sql_variant] NULL

    )

    CREATE FUNCTION fnc (@AuditNVP AuditNVP READONLY)

    RETURNS int

    AS

    BEGIN

    DECLARE @ReturnValue int

    -- Do something with the NVP (hopefully somehting more useful than this)

    SELECT @ReturnValue = COUNT(*) FROM @AuditNVP

    RETURN @ReturnValue

    END

    Then in sql code

    DECLARE @AuditNVP AuditNVP

    INSERT INTO @AuditNVP (Name, Value) VALUES ('Item',1)

    INSERT INTO @AuditNVP (Name, Value) VALUES ('Item',2)

    SELECT dbo.fnc(@AuditNVP) -- get count of items. Pointless but proves a point 😉

    David Bridge
    David Bridge Technology Limited
    www.davidbridgetechnology.com

  • Greatly appreciated easy question after I struggled with yesterdays.

  • Nice easy one today.

    Perhaps it would have been a good idea to provide the appropriate BoL reference: CREATE FUNCTION (Transact-SQL) which contains the statement

    In multistatement table-valued functions, @return_variable is a TABLE variable, used to store and accumulate the rows that should be returned as the value of the function

    and that answers the question rather clearly - if some functions have to use a table variable, then certainly functions can use table variables.

    Tom

  • Also:

    table (Transact-SQL)

    table variables can be used in functions, stored procedures, and batches.

    http://msdn.microsoft.com/en-us/library/ms175010.aspx

  • So is someone going to ask tomorrow if we can use temp tables in UDFs? 😛

  • Nice and easy thank you.

Viewing 15 posts - 1 through 15 (of 25 total)

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