February 13, 2018 at 1:59 pm
Steve please have this post deleted.
February 13, 2018 at 2:25 pm
You could start by getting rid of the unnecessary cursor.
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
February 13, 2018 at 3:26 pm
GilaMonster - Tuesday, February 13, 2018 2:25 PMYou could start by getting rid of the unnecessary cursor.
Thank you for your response but could you please explain what all pieces I should get rid of to eliminate the cursor. I apologize for this but I am not that good in programming and unfortunately this has been handed over to me for review.
February 13, 2018 at 3:30 pm
It loops over one table and inserts the values, one by one, into another table. That's not hard to replace with a single insert.
You get better at programming by doing it, not by someone doing it for you, so give it a try.
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
February 13, 2018 at 3:37 pm
GilaMonster - Tuesday, February 13, 2018 3:30 PMIt loops over one table and inserts the values, one by one, into another table. That's not hard to replace with a single insert.
You get better at programming by doing it, not by someone doing it for you, so give it a try.
I agree with you and that is my pain point even if I keep doing it a hundred time I won't be able to get rid of it. I am too bad at this and that is the reason I hate programming the most. Honestly, I don't really like to ask such questions and make myself even look more stupid but unfortunately I am not that skilled either. I can definitely give it a shot but I am sure I won't end up landing anywhere.
February 14, 2018 at 12:18 am
ffarouqi - Tuesday, February 13, 2018 1:59 PMIs there a better way or a more efficient way to write the attached stored proc that leans on to following best practice solution for writing a stored proc. For e.g can I add a try/catch block in this existing code or should I instead of declaring table variable should use temp tables etc. Any input would be highly appreciated.
Yes there are better ways of doing this.
😎
Looking through the code, everything there can be optimized with this one exception
ALTER PROCEDURE [dbo].[prEdPlanbyState]
February 14, 2018 at 12:29 am
Eirikur Eiriksson - Wednesday, February 14, 2018 12:18 AMffarouqi - Tuesday, February 13, 2018 1:59 PMIs there a better way or a more efficient way to write the attached stored proc that leans on to following best practice solution for writing a stored proc. For e.g can I add a try/catch block in this existing code or should I instead of declaring table variable should use temp tables etc. Any input would be highly appreciated.Yes there are better ways of doing this.
😎
Looking through the code, everything there can be optimized with this one exception
ALTER PROCEDURE [dbo].[prEdPlanbyState]
Wow...really I never thought about it. Okay so actions speak louder than words so could you please optimize everything except for the "Alter Proc".
February 14, 2018 at 12:45 am
ffarouqi - Wednesday, February 14, 2018 12:29 AMEirikur Eiriksson - Wednesday, February 14, 2018 12:18 AMffarouqi - Tuesday, February 13, 2018 1:59 PMIs there a better way or a more efficient way to write the attached stored proc that leans on to following best practice solution for writing a stored proc. For e.g can I add a try/catch block in this existing code or should I instead of declaring table variable should use temp tables etc. Any input would be highly appreciated.Yes there are better ways of doing this.
😎
Looking through the code, everything there can be optimized with this one exception
ALTER PROCEDURE [dbo].[prEdPlanbyState]Wow...really I never thought about it. Okay so actions speak louder than words so could you please optimize everything except for the "Alter Proc".
Are you asking me to do your work for free?
😎
February 14, 2018 at 1:35 am
ffarouqi - Wednesday, February 14, 2018 12:29 AMWow...really I never thought about it. Okay so actions speak louder than words so could you please optimize everything except for the "Alter Proc".
Table variables are slow (and you can probably manage with only one or even none).
Cursors are slow
Your string split is probably slow (can't tell, it wasn't included)
The variable assignments can be done in a single statement.
Can't tell how the final insert can be optimised. The multiple DISTINCTS are probably unnecessary though.
ffarouqi - Tuesday, February 13, 2018 3:37 PMI can definitely give it a shot but I am sure I won't end up landing anywhere.
So give it a shot. You'll learn a lot more by trying and getting suggestions than by someone doing it for you.
If you want your code (not just this) optimising by someone else, suggest to your boss that you get a consultant in to look at it.
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
February 14, 2018 at 2:17 am
GilaMonster - Wednesday, February 14, 2018 1:35 AMffarouqi - Wednesday, February 14, 2018 12:29 AMWow...really I never thought about it. Okay so actions speak louder than words so could you please optimize everything except for the "Alter Proc".Table variables are slow (and you can probably manage with only one or even none).
Cursors are slow
Your string split is probably slow (can't tell, it wasn't included)
The variable assignments can be done in a single statement.
Can't tell how the final insert can be optimised. The multiple DISTINCTS are probably unnecessary though.ffarouqi - Tuesday, February 13, 2018 3:37 PMI can definitely give it a shot but I am sure I won't end up landing anywhere.So give it a shot. You'll learn a lot more by trying and getting suggestions than by someone doing it for you.
If you want your code (not just this) optimising by someone else, suggest to your boss that you get a consultant in to look at it.
One thing would be the table variables, could be replaced by CTEs.
😎
Wealth of antipatterns in this code; multiple table variables, cursor using table valued function, multi-valued input parameter, distinct selection from a table valued function etc.
February 14, 2018 at 4:26 am
Eirikur Eiriksson - Wednesday, February 14, 2018 2:17 AMGilaMonster - Wednesday, February 14, 2018 1:35 AMffarouqi - Wednesday, February 14, 2018 12:29 AMWow...really I never thought about it. Okay so actions speak louder than words so could you please optimize everything except for the "Alter Proc".Table variables are slow (and you can probably manage with only one or even none).
Cursors are slow
Your string split is probably slow (can't tell, it wasn't included)
The variable assignments can be done in a single statement.
Can't tell how the final insert can be optimised. The multiple DISTINCTS are probably unnecessary though.ffarouqi - Tuesday, February 13, 2018 3:37 PMI can definitely give it a shot but I am sure I won't end up landing anywhere.So give it a shot. You'll learn a lot more by trying and getting suggestions than by someone doing it for you.
If you want your code (not just this) optimising by someone else, suggest to your boss that you get a consultant in to look at it.
One thing would be the table variables, could be replaced by CTEs.
😎
Very likely. I don't really have time to do more than glance over it though. Got paying clients stuff to work on, and a conference next week.
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
February 14, 2018 at 5:55 am
ffarouqi - Tuesday, February 13, 2018 3:37 PMGilaMonster - Tuesday, February 13, 2018 3:30 PMIt loops over one table and inserts the values, one by one, into another table. That's not hard to replace with a single insert.
You get better at programming by doing it, not by someone doing it for you, so give it a try.I agree with you and that is my pain point even if I keep doing it a hundred time I won't be able to get rid of it. I am too bad at this and that is the reason I hate programming the most. Honestly, I don't really like to ask such questions and make myself even look more stupid but unfortunately I am not that skilled either. I can definitely give it a shot but I am sure I won't end up landing anywhere.
Just curious then... what is the job description for your current position?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 14, 2018 at 7:11 am
If you want to have any chance of being helped. I suggest that you start with the best practices to post in forums.
How to Post Performance Problems - SQLServerCentral
How to post a T-SQL question on a public forum | spaghettidba
February 14, 2018 at 8:04 am
ffarouqi - Tuesday, February 13, 2018 1:59 PMSteve please have this post deleted.
I couldn't help but click when I saw the title "Please delete this post".
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply