Is it possible to declare a local variable depending on the case and then fire a common subquery?
SELECT CASE WHEN TABLE.TYPE = 'STUDENT' variable = "UNIVERSITY" WHEN TABLE.TYPE = 'EMPLOYEE' variable = "EMPLOYER" (Some big query here it has a common joins / groupings but the variable changes) END AS NAME FROM TABLE
Looking for a SQL Server solution.
Scenario is like this - I have a query that lists some member information . Now I need to get some addendum data to an existing query - I mean result set won't change . I can actually join but then I have to filter out many things - Does that make sense ? Imagine I was display all the members in the table and someone asks me to show the univeristy name or the employer name . And the biggest problem is a member can have more than one university he attended - same for employer . Isn't joins really bad on performance in this case ? Since there are many one to many stuff . Also please note I finally display only 10 records as part of pagination so I thought I should do a case statement .