Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2012
    Posts
    2

    Smile Unanswered: Convert vba function to TSQL

    Hello,
    I am new to trans sql. How can I convert the following attached vba access function to TSQL.

    Any help would be greatly appreciated.
    Thanks
    Tuandelia
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Rather than asking us to decipher your vba code, please just state the task you are trying to perform. What are the business rules, and what does your data look like?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Dec 2012
    Posts
    2
    HI Again,
    Say I have

    tbl001_step1_Sort_order

    Auto_ID, ClaimantID, SubpacketName, Docid, ForceDocStart
    1,1,1,"",Y
    2,1,2,"",Y
    3,1,2,"",
    4,2,1,"",Y
    5,2,3,"",Y
    6,2,3,"",Y
    7,3,1,"",Y
    8,3,5,"",Y
    9,3,5,"",Y
    10,4,1,"",Y


    I need to update DOCID when Forcestart is not null and increment when a change to subpacket or the claimantID has occurred...

    Final results
    Auto_ID, ClaimantID, SubpacketName, Docid, ForceDocStart
    1,1,1,1,Y
    2,1,2,2,Y
    3,1,2,2,""
    4,2,1,1,Y
    5,2,3,2,Y
    6,2,3,3,Y
    7,3,1,1,Y
    8,3,5,2,Y
    9,3,5,3,Y
    10,4,1,1,Y

    Any help greatly appreciated.

  4. #4
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Your VBA function isn't actually a function, as it takes no arguments and returns no value.

    T-SQL has some looping functionality, so you could probably work your business logic* into that:
    • Take the required records into a cursor
    • Pick up the key values into variables
    • Compare the key values and derive the required doc ID
    • Update the current cursor's record
    • Loop to the next record


    * As an aside, I something think that "business logic" is an oxymoron on par with "military intelligence"...
    10% of magic is knowing something that no-one else does. The rest is misdirection.

Posting Permissions

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