I have a complex SELECT statement in which it SELECTS about 12 different fields FROM 10 different tables (from 2 different databases) and WHERE there are a bunch of WHERE clauses depending on user entry.
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!
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!