Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complex SQL - what would be the best solution?
Message
From
09/09/2008 11:49:02
 
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:
01346087
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I have a complex SQL statement consisting of
>
>select * from (first select statement UNION another select UNION another select...) order by
>
>This is defined as a string property of my page class.
>
>Now, I have a field IsActive and in general I want to only select active people. So, I can add condition IsActive = 1 to all union statements.
>
>However, I added a new condition to our SQLQueryBuilder to be able to show inactive people or all people regardless on the status.
>
>The question is - how should I handle this situation now?
>
>Check my query_str for the IsActive in it (BTW, when I tried to see Help for IndexOf it opened some unrelevant content after I pressed F1 in VS2008 having IndexOf highlighted) and add this condition if it's not there - but how then both cases should be handled?
>
>Do you have any good ideas for me?
>
>Thanks in advance.


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)
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