June 27, 2019 at 12:00 am
Comments posted to this topic are about the item Reducing Round Trips
June 27, 2019 at 5:18 am
Nice, easy question, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
โlibera tute vulgaris exโ
June 27, 2019 at 12:39 pm
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;");
June 27, 2019 at 3:45 pm
Reworded slightly. It would be one trip with that code.
I was trying to raise awareness of the simplicity of sp_prepexec().
June 27, 2019 at 4:13 pm
Cool, thanks for confirming. You definitely achieved your goal of raising awareness of sp_prepexec() - I'll remember that one for the future ๐
June 28, 2019 at 9:45 am
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.
June 29, 2019 at 8:29 am
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.
July 1, 2019 at 8:18 am
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