I have a fairly large and nasty query that has for example employee id in it among other fields. Can I create and report that creates a sheet for each employee id? For example you can build a report that groups by employee id I would just need it to create a new sheet instead of a page break?
You would need to use a loop dataset in automation. Use a driving query that selected a distinct list of employeed id numbers. Then set that value in a variable. Execute a query that filters on the current id and export that to an excel file.
If you export to the same excel file for each execution it will put the result set into a new worksheet. See my Blog for examples.
Check out attachement (was created in TDA 2.5)
0) Automation File : dept_emp.tas
Master Query : dept.sql
Child Query : emp.sql
Export Wizard Template : emp_exp_temp.txp
Output Excel file : emp_emp1.xls
I was not able to use Master query dataset value nor a variable value in loop dataset Child query as a parameter.
So use find/replace in the emp.sql file.
You are very close in having this script work. Please see attached changes. (Note: I had to change to my connection so change them back for your use)
Here is what I did:
You need to have a template of the SQL file so that you can change the value. I added empbak.sql to use as the template. When you do a find and replace it will alwyas find the “xdeptno” and replace with value and write to emp.sql. If you don’t use a template file it will overwrite the “xdeptno” and subsequent loops will not do the proper find and replace.
Use Select to File instead of a Export Wizard template for the export. I like to do this because I added the deptno in the file name to make each export unique. Is that how you wanted it? If not use the same file and it will create a new worksheet.
You don’t need the last fnd and replace as the loop will handle it.
I still like using a bind var in my SQL instead of the find and replace. Attached is an example of this. I am using the attached sql file in the script along with an initializing var activity.
I still like using a bind var in my SQL instead of the find and replace. Attached is an example of this. I am using the attached sql file in the script along with an initializing var activity.