February 7, 2018 at 7:18 am
msimone - Friday, February 2, 2018 12:52 AMThanks for all, yours opinions are importants for me.
Please see my and other folks comments that tell you that your version is actually faulty because it doesn't actually do the same thing as the first code. The first code is also a total misuse of dynamic SQL and demonstrates no knowledge of that NULLs do.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 7, 2018 at 7:20 am
RandomStream - Friday, February 2, 2018 5:48 PMmsimone - Friday, February 2, 2018 12:52 AMThanks for all, yours opinions are importants for me.If you want to go beyond opinions, spend some time with this: Understanding Performance Mysteries
Better than that, their team needs a good course on the basics of querying, the basics of stored procedures, the basics of how NULL operates, and the basics of testing for correct results. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
February 7, 2018 at 7:37 am
Hello Jeff, thank you for yours recommendations.
There is an error in the second proc, is "id>=@id", not "@id>=@id"
In the first, if you pass null on @Id, return all rows; if you pass a value, return one row if exists.
In the second,If you pass a value for id and 1 for @rows, return one row if exists; if you pass a value lesser than all rows for @id and a big number in @rows, return all rows (the developer knows then logical business)
I would say that the procs do the same, although they seem differents.
The second proc do more things, the developer decides.
February 7, 2018 at 8:26 am
msimone - Wednesday, February 7, 2018 7:37 AMHello Jeff, thank you for yours recommendations.
There is an error in the second proc, is "id>=@id", not "@id>=@id"
In the first, if you pass null on @Id, return all rows; if you pass a value, return one row if exists.
In the second,If you pass a value for id and 1 for @rows, return one row if exists; if you pass a value lesser than all rows for @id and a big number in @rows, return all rows (the developer knows then logical business)
I would say that the procs do the same, although they seem differents.
The second proc do more things, the developer decides.
And using the 2nd code you have no guarantee what rows will be returned with execution of the query as there is no ORDER BY.
February 7, 2018 at 10:27 am
Lynn Pettis - Wednesday, February 7, 2018 8:26 AMmsimone - Wednesday, February 7, 2018 7:37 AMHello Jeff, thank you for yours recommendations.
There is an error in the second proc, is "id>=@id", not "@id>=@id"
In the first, if you pass null on @Id, return all rows; if you pass a value, return one row if exists.
In the second,If you pass a value for id and 1 for @rows, return one row if exists; if you pass a value lesser than all rows for @id and a big number in @rows, return all rows (the developer knows then logical business)
I would say that the procs do the same, although they seem differents.
The second proc do more things, the developer decides.And using the 2nd code you have no guarantee what rows will be returned with execution of the query as there is no ORDER BY.
And will have erratic performance. I keep fixing code of similar forms in client systems.
Don't write procedures that do multiple things. They're harder to debug and perform terribly.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply