Is Dynamic SQL okay when it uses no user fields in its input?

  • Okay. Well, I am still a young programmer and I can't say I'm set in my ways yet, because everytime I do a new project, it seems I'm finding better ways of doing things and wishing I had done them that new way all the time.

    I will try out your suggestion on my next project and see if I like it. 🙂

    Thanks for the help.

  • Cool. I still find on each new project that I wish I had known about such and such way of doing things before. That is actually a good thing. It means you are still striving to better yourself. The best way to do that is to try new ways of doing the same old thing. Hope your next one goes well and glad to hear you like my suggestions. 😛 Now I just hope they don't suck for you.

    _______________________________________________________________

    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/

  • LOL I have a real world example of why using a stored proc saved me plenty of time. We have a financial application that is used by a number of our accountants to enter our AP payments. When selecting a vendor and payment address we populate some of the data inputs with historical data as defaults. This has worked perfectly for quite some time until late afternoon yesterday when they got an idea.

    They want me to use a table with default data so they can enter more details than was posted the last time (currently the system just uses the last posted payment as the new defaults). The change now is to first look in the this new defaults table and use those, if it doesn't find any defaults for the current vendor then use the most recently posted data.

    I know that is all very confusing to read but basically now instead of just a simple select, it is a select, if no rows found then do a different select. This would have required some changes if using pass through queries. You would have to first retrieve the resultset from the new default table. If there are no rows, do another query from the database to the other table. Sound familiar?

    Because I used a stored procedure all I had to do was change the stored proc code. The parameter list was unchanged so no changes were required to the front end at all. I added some conditional checking in my proc and the whole was done and in production in just a couple hours.

    _______________________________________________________________

    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/

  • That's a great real world example. Thanks for that. On the web applications that I've built, I've never done anything with default values, mainly because I work with applications that register patients or enter orders for patients, and there can pretty much never be default values, because we want the doctor or nurse or whoever to be held more accountable for the values they're entering in these kinds of forms instead of getting used to default values being in certain places. Although, I'm sure some equally confusing scenario will come up at some point. Administration always gets "ideas" on how to do things better...and everytime that happens it means more work for me! 🙂 Oh well, job security.

    Thanks again.

Viewing 4 posts - 16 through 19 (of 19 total)

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