VISUAL STUDIO VB - Opinion on running large queries setting temp tables - what do you use

More of an opinion or guidance because I want to do this the correct and acceptable way.
I have large queries that take bits of tables, create temp tables and queries the temp tables and finally get a dataset.
Should I use a stringbuilder or type the whole query into a string?
Should I use temptables or table variables?
Should I create a procedure - subroutine?
ralphp1355Asked:
Who is Participating?
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
create temp tables and queries the temp tables and finally get a dataset
Only if those temp tables are a very small subset of the large queries. Otherwise you'll have performance issues.

How big are the large tables? With the correct indexes and maybe with partitions you won't need any workaround to query the tables.
Views also may be an interesting solution.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Stored Procs and/or UDFs should be preferred hen possible. They offer speed and reusability that dynamic queries don't have
0
 
Scott PletcherSenior DBACommented:
1) Not critical either way.  Typically you'll build up the string to make the logic easier to follow/change

2) 100% temp table; this will ultimately be critical for performance

3) a proc will save some slight time, but it likely won't be enough to make a huge difference once way or the other, unless your server is already at/near max cpu usage
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.