Script Files
Script Files contain SQL statements to manipulate data and also include parameter statements to control the scope of the data returned by an
SQL statement. Normally an SQL statement includes the physical value of that sets the range of data the statement will operate on but when a
script includes many statements operating on the same range then the value of the range is set outside the of a statement and the statement
includes a reference to the parameter which is set outside of the parameter and substituted in the statement at run time.
Using as an example lines from the file “All_Projects.sqv” parameters are set immediately after the statements which drop the temporary
tables the script file will work with.
// Temporary tables
Drop Table Projects;
Drop Table Bateman;
Drop table task_codes;
Drop table Week_End;
Drop Table Bateman_Sum;
Drop Table Tasks_1065;
Drop Table Project_Tasks;
Drop Table Departments;
// Set Month start date;
PARAMETER_SET prmStr_1 = #01/26/2013#;
// Set Month end date;
PARAMETER_SET prmStr_2 = #02/22/2013#;
// Set start of current year parameter;
PARAMETER_SET prmStr_3 = #12/29/2012#;
// Set start of previous year parameter;
PARAMETER_SET prmStr_4 = #06/18/2011#;
// Set end of previous year parameter;
PARAMETER_SET prmStr_5 = #12/28/2012#;
One of the advantages of using parameters like this is that they can be used multiple times in the script file as data is accessed ormanipulated
to create a report.
*** This sets the range of the timesheet data the script file will work with.
Select * INTO Projects from lnkBEPL_Projects where lnkBEPL_Projects.UOM = "HOURS" AND lnkBEPL_Projects.ITEM_DATE BETWEEN
prmStr_1 AND prmStr_2;
*** This calculates the distance of a date from month start date and then determines which of the 5 weeks in the report range the data will fall
into
Alter Table Projects ADD COLUMN Week_NUM TEXT (1);
Alter Table Projects ADD COLUMN Date_Diff Integer;
Alter Table Projects ADD COLUMN Week_End Date;
Update Projects Set Projects.Date_Diff = ((Projects.ITEM_DATE - prmStr_1) mod 35);
Update Projects Set Projects.Week_End = Projects.ITEM_DATE + (6 - (Projects.Date_Diff Mod 7));
Update Projects SET Projects.Week_NUM = "5" where Projects.Date_Diff BETWEEN 28 AND 34;
Update Projects SET Projects.Week_NUM = "4" where Projects.Date_Diff BETWEEN 21 AND 27;
Update Projects SET Projects.Week_NUM = "3" where Projects.Date_Diff BETWEEN 14 AND 20;
Update Projects SET Projects.Week_NUM = "2" where Projects.Date_Diff BETWEEN 7 AND 13;
Update Projects SET Projects.Week_NUM = "1" where Projects.Date_Diff BETWEEN 0 AND 6;
For this query the accounting period runs from the first Saturday in a month to the last Friday in a week which may be in the next physical
month and results in either 4 or 5 week months.
As data is aggregated further information such as employee details and task description are added but this isn’t shown in this introduction but
if required is seen in the file “All_Projects.sqv”.
Select * into Bateman from Projects;
**** Example of SQL statements that manipulate the data into the form required to output into a worksheet where the day of the week is
matched with a date***
Alter Table Bateman ADD Column WEEK_END_DATE Date;
Alter Table Bateman ADD Column SATHRS Float;
Alter Table Bateman ADD Column SUNHRS Float;
Alter Table Bateman ADD Column MONHRS Float;
Alter Table Bateman ADD Column TUEHRS Float;
Alter Table Bateman ADD Column WEDHRS Float;
Alter Table Bateman ADD Column THUHRS Float;
Alter Table Bateman ADD Column FRIHRS Float;
Alter Table Bateman ADD Column STTOT Float;
***** initialise values
Update Bateman SET Bateman.SATHRS = 0.00;
Update Bateman SET Bateman.SUNHRS = 0.00;
Update Bateman SET Bateman.MONHRS = 0.00;
Update Bateman SET Bateman.TUEHRS = 0.00;
Update Bateman SET Bateman.WEDHRS = 0.00;
Update Bateman SET Bateman.THUHRS = 0.00;
Update Bateman SET Bateman.FRIHRS = 0.00;
***** assign timesheet hours based on the day of the week identified by the value of the modulo
Update Bateman SET Bateman.FRIHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 0;
Update Bateman SET Bateman.THUHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 1;
Update Bateman SET Bateman.WEDHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 2;
Update Bateman SET Bateman.TUEHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 3;
Update Bateman SET Bateman.MONHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 4;
Update Bateman SET Bateman.SUNHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 5;
Update Bateman SET Bateman.SATHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 6;
*****Calculate total hours worked in the week by an employee which is a line in a single record
Update Bateman SET Bateman.STTOT = Bateman.SATHRS + Bateman.SUNHRS + Bateman.MONHRS + Bateman.TUEHRS + Bateman.WEDHRS +
Bateman.THUHRS + Bateman.FRIHRS;
*****The values are then transferred to the table Bateman_Sum which is used as the source for data written to Excel
Select Bateman.PROJECT, Bateman.TASK, Bateman.Task_Desc, Bateman.EXPEND_TYPE, Sum( Bateman.SATHRS )AS SATHRS , SUM(
Bateman.SUNHRS) AS SUNHRS, SUM ( Bateman.MONHRS ) AS MONHRS , SUM ( Bateman.TUEHRS ) AS TUEHRS , SUM ( Bateman.WEDHRS )
AS WEDHRS , SUM ( Bateman.THUHRS ) AS THUHRS , SUM ( Bateman.FRIHRS ) AS FRIHRS , SUM ( Bateman.STTOT ) AS STTOT
,Bateman.EMPLOYEE, Bateman.CLASSDESCRIP , Bateman.Location ,Bateman.Week_NUM , Bateman.Week_End INTO Bateman_Sum from
Bateman GROUP BY Bateman.PROJECT , Bateman.TASK ,Bateman.Task_Desc, Bateman.Dept , Bateman.EMPLOYEE, Bateman.EXPEND_TYPE,
Bateman.CLASSDESCRIP, Bateman.Location, Bateman.Week_NUM,Bateman.Week_End ;
*****Transferring the data to Excel and identifying the spreadsheet to use
DDE Excel C:SQL_TestSpreadsheetsProjects_All.xls;
*****Identify worksheet to use
DDE Excel_Sheet Week1;
*****start writing to the worksheet
DDE Add_Header 1, Project , Employee Name , Type , Classification , Task , Task Description , Saturday , Sunday , Monday , Tuesday ,
Wednesday , Thursday , Friday , Total Hours , ;
// Get Current Week Ending for Report;
Select TOP 1 “Project Man-hours Week Ending -” & format ( Bateman_Sum.Week_End, “dd-mmm-yyyy") & “- for review” from
Bateman_Sum Where Bateman_Sum.Week_NUM = "1”;
DDE Insert_Row 1; //add a blank line to worksheet
DDE Sum_On_Change 1, 7, 14, Total for Project,;
// output employee hours per project to worksheet
Select Bateman_Sum.PROJECT, Bateman_Sum.EMPLOYEE, Bateman_Sum.EXPEND_TYPE, Bateman_Sum.CLASSDESCRIP,
Bateman_Sum.TASK, Bateman_Sum.Task_Desc, Bateman_Sum.SATHRS, Bateman_Sum.SUNHRS, Bateman_Sum.MONHRS,
Bateman_Sum.TUEHRS, Bateman_Sum.WEDHRS, Bateman_Sum.THUHRS, Bateman_Sum.FRIHRS, Bateman_Sum.STTOT from
Bateman_Sum Where Bateman_Sum.Week_NUM = "1" Order by Bateman_Sum.PROJECT, Bateman_Sum.EMPLOYEE, Bateman_Sum.TASK;
Usingthis workbook fromC:SQl_TestSpreadsheetsasanexample anextractforWeek1 isshownbelow
What the above shows that by running multiple SQL statements it is possible to take raw data from a database add values and provide a
meaningful report and by using parameters it is possible to provide a generic report that will output what the parameters determine.
Project Employee Name Classification Task Task Description Saturday Sunday Monday Tuesday Wednesday Thursday Friday Total Hours
Project Manhours Week Ending - 01-Jun-2012 - for review
C0001 McDonald, Doctor Douglas Colin DC A Process Engineer Principal A0010 8.00 8.00 8.00 8.00 8.00 40.00
Total for Project 8.00 8.00 8.00 8.00 8.00 40.00
M6031 Frearson, Mr. Russell RF AUS81082 R Cost Engineer A1015 1.00 1.00
Total for Project 1.00 1.00
M6037 Frearson, Mr. Russell RF AUS81082 R Cost Engineer P1000 1.00 1.00
M6037 Loveday, Mr. Grant Kelsey GK AUS238 Process Engineer Senior P1000 5.00 6.50 4.50 5.00 21.00
Total for Project 5.00 7.50 4.50 5.00 22.00
Script Files

More Related Content

PDF
Analyzing Air Quality Measurements in Macedonia with Apache Drill
PPTX
My SQL Events
DOCX
Introduction to SQL Report tool
DOCX
developer-ParkJaeHyung
DOCX
WhiteStar Ltd. Product Catalog
PDF
2015.11.29オープンガバメント推進協議会公開シンポジウム「オープンデータの国内外の現状とこれから」川島宏一氏
DOCX
ECU_CV_Russell Frearson Funct
PPTX
Chapter 10- Computer As Descrete Tools of Teaching, The Great Revolution
Analyzing Air Quality Measurements in Macedonia with Apache Drill
My SQL Events
Introduction to SQL Report tool
developer-ParkJaeHyung
WhiteStar Ltd. Product Catalog
2015.11.29オープンガバメント推進協議会公開シンポジウム「オープンデータの国内外の現状とこれから」川島宏一氏
ECU_CV_Russell Frearson Funct
Chapter 10- Computer As Descrete Tools of Teaching, The Great Revolution

Viewers also liked (17)

PDF
Colorbath final
PDF
15.08.28_Impact report_V3_SW
PPTX
Special features of rural development A Presentation By Mr Allah Dad Khan Vi...
PPTX
social science teacher- architect of nation
PPTX
Tilt shift photography
PPTX
Show me the picture ed tech pres
PDF
Eng nigah hussain_packages
PPTX
Comunicación interactiva presentación
PDF
PDF
oracle 9i cheat sheet
PDF
Characterization of the 1-9-90 Roles within Commons-based Peer Production Com...
DOCX
User Manual_SQLVB Report Tool v2
PPT
Sqlplus
PPT
.NET Vs J2EE
PDF
Oracle sql tutorial
DOC
ETL QA
PPTX
PL/SQL Fundamentals I
Colorbath final
15.08.28_Impact report_V3_SW
Special features of rural development A Presentation By Mr Allah Dad Khan Vi...
social science teacher- architect of nation
Tilt shift photography
Show me the picture ed tech pres
Eng nigah hussain_packages
Comunicación interactiva presentación
oracle 9i cheat sheet
Characterization of the 1-9-90 Roles within Commons-based Peer Production Com...
User Manual_SQLVB Report Tool v2
Sqlplus
.NET Vs J2EE
Oracle sql tutorial
ETL QA
PL/SQL Fundamentals I
Ad

Similar to Script Files (20)

DOCX
All_Projects SQL Script
PPT
Dynamically Evolving Systems: Cluster Analysis Using Time
PPT
MMYERS Portfolio
PDF
Assignment Details There is a .h file on Moodle that provides a defi.pdf
PDF
CMPSC 122 Project 1 Back End Report
PPTX
Chris Seebacher Portfolio
PDF
Chris Bull's Bi Portfolio
PPTX
MYSQL DATA TYPES for newbies helpful.pptx
PPT
My Portfolio
PPT
My Portfolio
PPT
PDF
C-Project Report-SSRS
DOCX
In this assignment, you will continue working on your application..docx
PDF
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
PDF
Modify the Time classattached to be able to work with Date.pdf
PPT
e computer notes - Date time functions
PPTX
Business Intelligence Portfolio
PDF
Visual Programming Lacture Nine 9 Structure.pdf
PDF
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
PPT
Collaborate 2009 - Migrating a Data Warehouse from Microsoft SQL Server to Or...
All_Projects SQL Script
Dynamically Evolving Systems: Cluster Analysis Using Time
MMYERS Portfolio
Assignment Details There is a .h file on Moodle that provides a defi.pdf
CMPSC 122 Project 1 Back End Report
Chris Seebacher Portfolio
Chris Bull's Bi Portfolio
MYSQL DATA TYPES for newbies helpful.pptx
My Portfolio
My Portfolio
C-Project Report-SSRS
In this assignment, you will continue working on your application..docx
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Modify the Time classattached to be able to work with Date.pdf
e computer notes - Date time functions
Business Intelligence Portfolio
Visual Programming Lacture Nine 9 Structure.pdf
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
Collaborate 2009 - Migrating a Data Warehouse from Microsoft SQL Server to Or...
Ad

Script Files

  • 1. Script Files Script Files contain SQL statements to manipulate data and also include parameter statements to control the scope of the data returned by an SQL statement. Normally an SQL statement includes the physical value of that sets the range of data the statement will operate on but when a script includes many statements operating on the same range then the value of the range is set outside the of a statement and the statement includes a reference to the parameter which is set outside of the parameter and substituted in the statement at run time. Using as an example lines from the file “All_Projects.sqv” parameters are set immediately after the statements which drop the temporary tables the script file will work with. // Temporary tables Drop Table Projects; Drop Table Bateman; Drop table task_codes; Drop table Week_End; Drop Table Bateman_Sum; Drop Table Tasks_1065; Drop Table Project_Tasks; Drop Table Departments; // Set Month start date; PARAMETER_SET prmStr_1 = #01/26/2013#; // Set Month end date; PARAMETER_SET prmStr_2 = #02/22/2013#; // Set start of current year parameter;
  • 2. PARAMETER_SET prmStr_3 = #12/29/2012#; // Set start of previous year parameter; PARAMETER_SET prmStr_4 = #06/18/2011#; // Set end of previous year parameter; PARAMETER_SET prmStr_5 = #12/28/2012#; One of the advantages of using parameters like this is that they can be used multiple times in the script file as data is accessed ormanipulated to create a report. *** This sets the range of the timesheet data the script file will work with. Select * INTO Projects from lnkBEPL_Projects where lnkBEPL_Projects.UOM = "HOURS" AND lnkBEPL_Projects.ITEM_DATE BETWEEN prmStr_1 AND prmStr_2; *** This calculates the distance of a date from month start date and then determines which of the 5 weeks in the report range the data will fall into Alter Table Projects ADD COLUMN Week_NUM TEXT (1); Alter Table Projects ADD COLUMN Date_Diff Integer; Alter Table Projects ADD COLUMN Week_End Date; Update Projects Set Projects.Date_Diff = ((Projects.ITEM_DATE - prmStr_1) mod 35); Update Projects Set Projects.Week_End = Projects.ITEM_DATE + (6 - (Projects.Date_Diff Mod 7));
  • 3. Update Projects SET Projects.Week_NUM = "5" where Projects.Date_Diff BETWEEN 28 AND 34; Update Projects SET Projects.Week_NUM = "4" where Projects.Date_Diff BETWEEN 21 AND 27; Update Projects SET Projects.Week_NUM = "3" where Projects.Date_Diff BETWEEN 14 AND 20; Update Projects SET Projects.Week_NUM = "2" where Projects.Date_Diff BETWEEN 7 AND 13; Update Projects SET Projects.Week_NUM = "1" where Projects.Date_Diff BETWEEN 0 AND 6; For this query the accounting period runs from the first Saturday in a month to the last Friday in a week which may be in the next physical month and results in either 4 or 5 week months. As data is aggregated further information such as employee details and task description are added but this isn’t shown in this introduction but if required is seen in the file “All_Projects.sqv”. Select * into Bateman from Projects; **** Example of SQL statements that manipulate the data into the form required to output into a worksheet where the day of the week is matched with a date*** Alter Table Bateman ADD Column WEEK_END_DATE Date; Alter Table Bateman ADD Column SATHRS Float; Alter Table Bateman ADD Column SUNHRS Float; Alter Table Bateman ADD Column MONHRS Float; Alter Table Bateman ADD Column TUEHRS Float; Alter Table Bateman ADD Column WEDHRS Float; Alter Table Bateman ADD Column THUHRS Float; Alter Table Bateman ADD Column FRIHRS Float;
  • 4. Alter Table Bateman ADD Column STTOT Float; ***** initialise values Update Bateman SET Bateman.SATHRS = 0.00; Update Bateman SET Bateman.SUNHRS = 0.00; Update Bateman SET Bateman.MONHRS = 0.00; Update Bateman SET Bateman.TUEHRS = 0.00; Update Bateman SET Bateman.WEDHRS = 0.00; Update Bateman SET Bateman.THUHRS = 0.00; Update Bateman SET Bateman.FRIHRS = 0.00; ***** assign timesheet hours based on the day of the week identified by the value of the modulo Update Bateman SET Bateman.FRIHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 0; Update Bateman SET Bateman.THUHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 1; Update Bateman SET Bateman.WEDHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 2; Update Bateman SET Bateman.TUEHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 3; Update Bateman SET Bateman.MONHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 4; Update Bateman SET Bateman.SUNHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 5; Update Bateman SET Bateman.SATHRS = Bateman.QUANTITY WHERE (Bateman.Week_End - Bateman.ITEM_DATE) mod 7 = 6;
  • 5. *****Calculate total hours worked in the week by an employee which is a line in a single record Update Bateman SET Bateman.STTOT = Bateman.SATHRS + Bateman.SUNHRS + Bateman.MONHRS + Bateman.TUEHRS + Bateman.WEDHRS + Bateman.THUHRS + Bateman.FRIHRS; *****The values are then transferred to the table Bateman_Sum which is used as the source for data written to Excel Select Bateman.PROJECT, Bateman.TASK, Bateman.Task_Desc, Bateman.EXPEND_TYPE, Sum( Bateman.SATHRS )AS SATHRS , SUM( Bateman.SUNHRS) AS SUNHRS, SUM ( Bateman.MONHRS ) AS MONHRS , SUM ( Bateman.TUEHRS ) AS TUEHRS , SUM ( Bateman.WEDHRS ) AS WEDHRS , SUM ( Bateman.THUHRS ) AS THUHRS , SUM ( Bateman.FRIHRS ) AS FRIHRS , SUM ( Bateman.STTOT ) AS STTOT ,Bateman.EMPLOYEE, Bateman.CLASSDESCRIP , Bateman.Location ,Bateman.Week_NUM , Bateman.Week_End INTO Bateman_Sum from Bateman GROUP BY Bateman.PROJECT , Bateman.TASK ,Bateman.Task_Desc, Bateman.Dept , Bateman.EMPLOYEE, Bateman.EXPEND_TYPE, Bateman.CLASSDESCRIP, Bateman.Location, Bateman.Week_NUM,Bateman.Week_End ; *****Transferring the data to Excel and identifying the spreadsheet to use DDE Excel C:SQL_TestSpreadsheetsProjects_All.xls; *****Identify worksheet to use DDE Excel_Sheet Week1; *****start writing to the worksheet DDE Add_Header 1, Project , Employee Name , Type , Classification , Task , Task Description , Saturday , Sunday , Monday , Tuesday , Wednesday , Thursday , Friday , Total Hours , ; // Get Current Week Ending for Report;
  • 6. Select TOP 1 “Project Man-hours Week Ending -” & format ( Bateman_Sum.Week_End, “dd-mmm-yyyy") & “- for review” from Bateman_Sum Where Bateman_Sum.Week_NUM = "1”; DDE Insert_Row 1; //add a blank line to worksheet DDE Sum_On_Change 1, 7, 14, Total for Project,; // output employee hours per project to worksheet Select Bateman_Sum.PROJECT, Bateman_Sum.EMPLOYEE, Bateman_Sum.EXPEND_TYPE, Bateman_Sum.CLASSDESCRIP, Bateman_Sum.TASK, Bateman_Sum.Task_Desc, Bateman_Sum.SATHRS, Bateman_Sum.SUNHRS, Bateman_Sum.MONHRS, Bateman_Sum.TUEHRS, Bateman_Sum.WEDHRS, Bateman_Sum.THUHRS, Bateman_Sum.FRIHRS, Bateman_Sum.STTOT from Bateman_Sum Where Bateman_Sum.Week_NUM = "1" Order by Bateman_Sum.PROJECT, Bateman_Sum.EMPLOYEE, Bateman_Sum.TASK;
  • 7. Usingthis workbook fromC:SQl_TestSpreadsheetsasanexample anextractforWeek1 isshownbelow What the above shows that by running multiple SQL statements it is possible to take raw data from a database add values and provide a meaningful report and by using parameters it is possible to provide a generic report that will output what the parameters determine. Project Employee Name Classification Task Task Description Saturday Sunday Monday Tuesday Wednesday Thursday Friday Total Hours Project Manhours Week Ending - 01-Jun-2012 - for review C0001 McDonald, Doctor Douglas Colin DC A Process Engineer Principal A0010 8.00 8.00 8.00 8.00 8.00 40.00 Total for Project 8.00 8.00 8.00 8.00 8.00 40.00 M6031 Frearson, Mr. Russell RF AUS81082 R Cost Engineer A1015 1.00 1.00 Total for Project 1.00 1.00 M6037 Frearson, Mr. Russell RF AUS81082 R Cost Engineer P1000 1.00 1.00 M6037 Loveday, Mr. Grant Kelsey GK AUS238 Process Engineer Senior P1000 5.00 6.50 4.50 5.00 21.00 Total for Project 5.00 7.50 4.50 5.00 22.00