• karthikeyan (6/8/2009)


    1) What is mean by pseudo cursor?

    Pusedocursor is a name that some people (including me) use for the SQL Server (and Sybase too, I believe) trick of being able to assign both to and from variables for every row of a resultset. The typical example is the simple string concatenation trick that we often use:

    Declare @STR varchar(MAX)

    Set @STR = ''

    Select @STR = @STR + ',' + [name] From sys.columns

    Print @STR

    "pre-allocate and Stuff" trick popular with mutable strings

    2) what this trick will do?

    We used to call this "string mapping" back in the old days. Instead of reallocating the output string with every iteration, you estimate the likely size of the output string and pre-allocate the output string with that much blank space and use a LenPtr to keep track of how much of this buffer you have used. Then for each string you "MAP" or "STUFF" the current source string into the next available space after LenPtr and then update LenPtr to the new end. This is linear time ( O(n) ) because you only have to touch each input character once.

    (Heh. I was re-reading this and just realized that I got my "Left" and "Right" reversed! :blush: Yikes!)

    4) What LHS (Left-hand side) RHS (Right-hand side) function denotes exactly?

    LeftRight-hand Functions appear leftright of the assignment operator ("="):

    Set @STR = UPPER('Some text.')

    These are normal functions, and AFAIK, in T-SQL, all functions are LRHS.

    3) What RLHS (rightleft-hand side) function denotes exactly?

    RightLeft-hand Side functions appear on the rightleft-hand side and they usually do "special" things having to do with addressing the output property or variable. AFAIK, T-SQL does not have any, but in some languages, STUFF is a RLHS:

    STUFF(@str, offset, len) = 'foo'

    This example would overwrite the output string (@str) with the input string starting at 'offset' for 'len' characters. The difference between this and the RHS STUFF() function in T-SQL is that the LHS version does not return anything, it actually does write over the characters of the @STR variable.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]