There is one field, say EmpID, in which:
IF EmpID = xx123 THEN the SELECT statement shouldn't be so complex b/c it can't go that deep into the tree of relationships.
ELSE SELECT the COMPLEX query...
So let's say I enter a certain REGION to search for my Employees and I pick WEST, then my SELECT statement should EXECUTE both SELECT statements (if there are 2 of them?) and return something like this:
EmpID....Region....Market......F_ID......Loc
ab323.....WEST......Sales.......123456...Texas
xx123.....WEST......Sales.......unavail...unavail.
cc848......WEST......Marketing..393921...California
As you can see, if EmpID is anything but 'xx123' then all fields are approachable, but if it is 'xx123' then some fields aren't thus it should be a small SELECT statement with 1 or 2 JOIN statements.
SELECT t1.EmpID, t2.Region, t3.Market, t4.F_ID, t5.Loc ...
FROM t1 ... INNER JOIN ... t5
WHERE t2.Region like USER INPUT
Your assistance will be greatly appreciated!I dont think I get the actual problem in hand ... But from what I understand ...
1. You can write a Dynamic SQL to build your own Select query based on some user inputs
or
2. If the values are part of some thing then you can use the CASE expression to hide certain column values as
Select Case Col1 When 'test' then <<Show Col>> End [Hidden Col], Col2 ...
From <<Table>> ...|||Not knowing the table structure I can't say for sure but you might think about using a union statement for something like this. The Union is suitable if the records can be "stacked":
-- first the complex query
Select EmpID, Region, Market, F_ID, Loc FROM etc. Where whaterver.
UNION
-- then the simple query
Select EmpID, Region, Market, '' as F_ID, '' as Loc FROM etc. Where whaterver
No comments:
Post a Comment