To build dynamic SQL Query using some conditions: Pseudo code required
831217Mar 6 2011 — edited Mar 7 2011Hi,
I have a requirement where in i have to build a dynamic query based on one count.
Some details on requirement:
1) It's a Proc where i need to return some columns
2) There are some fix set of columns
3) Based on one Count column, i have to decide the rest of the columns.
Consider there is an employee who can work on 'N' number of assignments.
For a particular employee i have to return all the predefined details of assignments like:
1) Assignment Name
2) Assignmanet Id
3) Assignemnt Start Date
4) Assignment End Date
This 'N' can vary from employee to employee. Based on which i have to return my result set. For instance if employee has 3 assignemnts, i have to return Fix columns( employee info) + (3*4) columns. Similarly if the employee has 4 assignments, i will be returning Fix columns + (4*4) columns.
Certainly, the Employee ID is coming as an I/P parameter.
The source table is a vertical table having all details of the employee assignments.
Can anyone help me in coding this proc with the help of some pseudo code?