Help Needed in Avoiding RBAR

  • KGJ-Dev (1/20/2015)


    Thanks sean, in that case i am updating the amount. can both the syntax below results same?

    OUTPUT INSERTED.UserId

    OUTPUT Deleted.UserId

    If that column is not being updated or the update value is the same then yes those would result in the same value. If however you were trying to change the UserID then the values would be different. If it was me I would build this with the assumption that at some point that value will be update and use the most appropriate one.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sorry Gentleman, am little confused.

    I am not updating the UserId. i am just updating the Amount and always the amount will not be same because this process will update the amount but not UserId. So will both result the same?

    OUTPUT INSERTED.UserId

    OUTPUT Deleted.UserId

  • KGJ-Dev (1/20/2015)


    Sorry Gentleman, am little confused.

    I am not updating the UserId. i am just updating the Amount and always the amount will not be same because this process will update the amount but not UserId. So will both result the same?

    OUTPUT INSERTED.UserId

    OUTPUT Deleted.UserId

    Read my response again. In the process you are describing it sounds that the values would be the same so it doesn't make any real difference. You should however write your code to deal with the eventuality that at some point there will be a requirement to manually update that table. I have no idea what this data is or how it is used. You should use the most appropriate one in your situation. If you don't care then just pick one of them.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Great and got it. Thanks for your time

  • I'm going to backtrack a minute here and ask why you have a process to calculate your user account balances?

    Doesn't that imply that, between processing runs the balance is not up to date?

    Why not just skip the process altogether and simply calculate the current user account balance directly when needed( thus normalizing your data model in the process)?

    Edit: Unless of course this is homework, where I have seen much more odd types of assignments.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • ...

    Why not just skip the process altogether and simply calculate the current user account balance directly when needed( thus normalizing your data model in the process)?

    Edit: Unless of course this is homework, where I have seen much more odd types of assignments.

    I might think about couple of cases where it is applicable other than course homework:

    1. This is exactly the query which executes "directly when needed", may be output feed or report...

    2. Datawarehouse (OLAP)

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Hi Dwain,

    Thanks for your reply and i didn't explain whole concept of my requirement. i just mentioned the requirement where the technical task comes into picture. Currently it is doing row by row through front end and i love to make this concept in single shot.

    I could realize there are grey area in the concept which i couldn't share over the internet.

    apologize for the grey area's.

    thanks

Viewing 7 posts - 16 through 21 (of 21 total)

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