Reducing Round Trips

  • Comments posted to this topic are about the item Reducing Round Trips

  • Nice, easy question, thanks Steve

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    โ€œlibera tute vulgaris exโ€

  • Is it not one round trip if you put both statements in the same batch? In Java I think the following is only 1 round trip:

    Statement stmt = cn.createStatement();
    ResultSet rs = stmt.executeQuery("DECLARE @P1 int; \n" +
    "EXEC sp_prepare @P1 output, \n" +
    "N'@P1 int', \n" +
    "N'SELECT a FROM test_table WHERE b=@P1'; \n" +
    "EXEC sp_execute @P1, 3;");
  • Reworded slightly. It would be one trip with that code.

    I was trying to raise awareness of the simplicity of sp_prepexec().

  • Cool, thanks for confirming. You definitely achieved your goal of raising awareness of sp_prepexec() - I'll remember that one for the future ๐Ÿ™‚

  • Please clear it up for me. Why isn't an option to create a procedure. If i'm using that SQL snippet from an application with different parameters, i'd surely create a procedure. For me it seems to be easier to maintain too.

     

    • This reply was modified 4 years, 10 months ago by  palotaiarpad.
  • Hi Palotaiarpad.

    I think this is because the question states, "I need to code some SQL in my application", which means that it's an ad-hoc query from the application. Creating a stored procedure from the application code means that it's not a pre-existing stored procedure already in the DB. One wouldn't want to create a stored procedure for every ad-hoc query being done from the application (which reminds me, those procedures would probably have to be dropped afterwards too). The question is also looking to reduce round trips, and stored procedures have to be created in a batch by themselves, which would force two round trips if using that approach. On connections with high latency, those round trips can be a death sentence.

    If it was not an ad-hoc query and instead was a fairly static query that was going to be used a lot, then creating it as a stored procedure in the DB makes sense.

  • Ok, then it's due to my english knowledge. I missed the 'in' and understood it as 'for'. ๐Ÿ™‚

Viewing 8 posts - 1 through 7 (of 7 total)

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