Professional Web Applications Themes

how to declare a static var in UDF? - Microsoft SQL / MS SQL Server

Hello, I need to write an incremental number to a large table. I would like to create a UDF with a static var the increments itself and write that to the table in an Update SP. I would be grateful for any suggestions how to declare a static var in my UDF. Thanks, Rich *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!...

  1. #1

    Default how to declare a static var in UDF?

    Hello,

    I need to write an incremental number to a large table. I would like to
    create a UDF with a static var the increments itself and write that to
    the table in an Update SP. I would be grateful for any suggestions how
    to declare a static var in my UDF.

    Thanks,

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Rich Guest

  2. #2

    Default Re: how to declare a static var in UDF?

    You cannot do that with an UDF. If you are not using an identity column you
    can do something along the lines of :

    UPDATE tbl
    SET v = col = v + 1

    to sequentially increment the values. If you want to get the value to be
    stored within the session & be incremented you can use the SET CONTEXT_INFO
    option.

    --
    - Anith
    ( Please reply to newsgroups only )


    Anith Guest

  3. #3

    Default Re: how to declare a static var in UDF?

    Thank you for your reply. I humbly reveal that I am a tad ignorant to
    understand your explanation below. I have a tbl, tbl1 with 150 fields
    of which RowNum is a bigint column that I would like to populate
    sequentially. Would I be correct to interpret your explanation below as
    this:

    Declare v bigint
    Update tbl1 Set v = RowNum = v + 1

    which I would run in Query yzer? I think I am missing something.
    How do I set the Context_Infor?

    Thanks,
    Rich


     [/ref]
    You cannot do that with an UDF. If you are not using an identity column
    you
    can do something along the lines of :

    UPDATE tbl
    SET v = col = v + 1

    to sequentially increment the values. If you want to get the value to be
    stored within the session & be incremented you can use the SET
    CONTEXT_INFO
    option.

    --
    - Anith
    ( Please reply to newsgroups only )

    <<
    Rich

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Rich Guest

  4. #4

    Default Re: how to declare a static var in UDF?

    OK. I got it to work! Here is what I tried:

    Declare v bigint
    set v = 0
    update tblzzztest set v = testID = v + 1

    I had to initialize v as above, and then all the rows with testID
    populated correctly, sequentially.

    Many thanks for your help

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Rich Guest

Similar Threads

  1. Replies: 2
    Last Post: December 3rd, 12:47 AM
  2. Replies: 0
    Last Post: October 23rd, 08:36 PM
  3. #39242 [NEW]: Cannot declare a static array with an index
    By z_rules55 at hotmail dot com in forum PHP Bugs
    Replies: 0
    Last Post: October 23rd, 08:30 PM
  4. Replies: 3
    Last Post: October 5th, 03:04 PM
  5. Replies: 1
    Last Post: September 11th, 09:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139