Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A very unique situation
Message
 
 
To
04/02/2014 14:07:44
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01593091
Message ID:
01593193
Views:
24
>The following will avoid having to deal with a long WHERE IN clause as it will dump everything into #Temp and use it after to get the final SQL select command with all the fields that are needed.
>
>This example includes a sample example of collecting 9 keys. But, in real life, this would be a bunch of conditions to determine which keys I need to collect.
>
>
>SELECT Country.Numero INTO #Temp FROM Country WHERE Numero<10
>SELECT Country.Title_E,Country.Title_F FROM Country WHERE Numero IN (SELECT * FROM #Temp)
>
>
>The example shown above is just to demonstrate the approach. In real life, we have some very complicated SQL select commands but could use the same approach so to only collect the primary keys at first and then a simple select to get the rest of the fields.
>
>Is this pretty much a considered optimized approach to handle that situation?


I think you need to say where Numero IN (select Numero from #Temp)

--------------------
Now, it may perform better for complex scenarios (e.g. selecting keys only into temp table first and then all info for these keys). In simple cases it may not give performance gain or may even be slower than original direct query without using a temp table.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform