Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complex SQL - what would be the best solution?
Message
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01345823
Message ID:
01346096
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
>>Use a parameter (tinyint) in your query that will show you what you want, That parameter will accept 3 values:
>>0 - Inactive
>>1 - Active
>>2- all
>>Then build your where clause that way:
>>WHERE (@Parameter = 2 OR IsActive = @Parameter)
>
>Thanks, Borislav. This idea would not work for our particular scenario, but thanks.
>
>My question was more of does it matter in SQL where the condition is placed.
>
>In other words, having IsActive condition in each union is theoretically supposed to be better than having it as the last clause
>
>e.g. which SQL should perform better
>
>select * from (firstPart where IsActive UNION secondPart where IsActive etc.)
>
>versa
>
>select * from (fristPart union ....) where IsActive

Run both in SSMS and check the execution plan :-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform