Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONREM ----------------------------------------------------------------------------------------------REM Script: SOM_Dashboard_query.cmdREM Created: 2011/11/01REM Author: Brian FergussonREM Version: 1REM Description:REM This is the main script for extracting data for the Testing Statistics SOM Dashboard.REM The result of each dashboard query is outputted to a csv file.REM The queries are run for the previous month of data (Variable, date_code (set below), must be set to 1 for this mode).REM ----------------------------------------------------------------------------------------------SET DIR_INPUT=.\queriesSET DIR_OUTPUT=.\outputREM SET DIR_OUTPUT=\\auperanas01\Data\Transit\tempREM Disable debug modeSET DEBUG=NSET SERVER_TD=AUPERAMTD01SET SERVER_CQ=AUPERASQL05SET SERVER_JR=AUPERASQL05REM Versions of each query (for debugging)SET VER_TD=5SET VER_JR=3SET VER_CQ=8PUSHD .ECHO.ECHO Test Director Server: %SERVER_TD%ECHO Clear Quest Server: %SERVER_CQ%ECHO Jira Server: %SERVER_JR%REM get month. This is for the csv filenameSET month_qry=SQLCMD -S%SERVER_TD% -E -Q "SET NOCOUNT ON; select rtrim(year(DATEADD(mm,-1,CURRENT_TIMESTAMP))) + '_' + right('0' + rtrim(month(DATEADD(mm,-1,CURRENT_TIMESTAMP))),2)" -h-1 -s"," -WFOR /f "usebackq tokens=1,2 delims=_" %%A IN (`%month_qry%`) DO (SET year=%%ASET month=%%B)ECHO Query Month: %year%/%month%ECHO.ECHO Running SOM Dashboard queries for Month: %year%/%month%ECHO.REM query previous monthREM date_code is accessed in the sql scriptSET date_code=1CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_TD.csv" "Test Director" "-E"CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_CQ.csv" "Clear Quest" "-E"CALL :query_to_csv %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_JR.csv" "Jira" "-E"IF %DEBUG% == Y (REM This block of code is used for debugging purposes.REM It is not required in a live system, ie SET DEBUG=NREM Query data since 2009SET date_code=2CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_v%VER_TD%.csv" "Test Director" "-E"CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_v%VER_CQ%.csv" "Clear Quest" "-E"CALL :query_to_csv %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_JR_DEVI_v%VER_JR%.csv" "Jira" "-E"REM generate row data for issue investigation purposesREM query data for a specific debug date range, See Dashboard_query_init.sqlSET date_code=3CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD_TEST_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_rows_aug_to_oct_v%VER_TD%.csv" "Test Director" "-E"CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_rows_aug_to_oct_v%VER_CQ%.csv" "Clear Quest" "-E"CALL :query_to_csv %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_JR_DEVI_rows_aug_to_oct_v%VER_JR%.csv" "Jira" "-E")ECHO.ECHO Completed SOM Dashboard queries for Month: %year%/%month%ECHO.goto endREM ----------------------------------------------------------------------------------------------: query_to_csvREM Runs SQLCMD to run the specified query and output the result to the specified output file.REMREMREM Note: %~1: removes surrounding quotes on parameter %1SET server=%1SET inpfile=%~2SET outfile=%~3SET datatitle=%~4SET login=%~5ECHO Querying %datatitle% databases...ECHO Running %inpfile%ECHO Outputting to:%outfile%REM outsputs to csv using a comma separater (-s",") and includes a header and no trailing spaces (-W). Note: to remove headers use (-h-1)REM Run sqlcmd and remove dashed line after the column headerSQLCMD -S%server% %login% -i "%inpfile%" -o "%outfile%" -s"," -WREM SQLCMD -S%server% %login% -i "%inpfile%" -s"," -W | find /v "-----" > "%outfile%"ECHO Completed querying %datatitle% databases.ECHO.GOTO endpREM ----------------------------------------------------------------------------------------------:endPOPDREM pause:endp