Hi,
I have run one vbs script which call to SQL Script & giving me output to text file.I need output to excel file which is not coming on proper way .Please help me how do I get output in excel file.
VBS Script are:
' -------------------------------------------------------------------------------------
' runcomparereoprtsql.vbs - run SQL Server script files
' This version is specifically for running application batch SQL script (non-dba)
'
' Created: September 6, 2013
' author: vipin bansal (YX84)
' NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'
' This script requires a TRUSTED SQL SERVER CONNECTION !!!!
'
' the scheduler id AND password MUST BE IDENTICAL on BOTH 123 and
' idcsrv17 or this script will fail !!!!!
'
' NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'
' This script requires:
'
' K:\batch\scripts\SQLErrorSearch.txt
'
' for the findstr command step to search the output for error messages
'
' NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' positional parms: database name - required
' script file name - required
' force 0 return - optional - use "ZERO"
' script path - optional - DEFAULT is K:\batch\SQL
'
' separate parms with spaces (do not use commas)
'
' eg: cscript i:\sqlappmisc\scripts\sqg4@a05.vbs VitalObjects gtczua01 '
' -------------------------------------------------------------------------------------
Option Explicit ' Force explicit declarations
dim WshShell
dim strDate, strYear, strMonth, strDay, strHH, strMM
dim strDateStamp, objArgs, startdt, starttm, enddt, endtm, IntReturn
dim strReportFile, strISQL, strParms, strText, strCommand
dim strDbname, strScriptName, strSQLScript, strSQLPath, strForceZero
dim I, CRLF
'-- use the CHR function to value a variable with a carriage-return/line-feed
'-- this is for a pop-up window for error messages
CRLF = Chr(13) & Chr(10)
On Error Resume Next
'---- Get the command line args
'Set objArgs = Wscript.Arguments
startdt = Date
starttm = Time
' -- the code below will parse together the datetimestamp in full YYYYMMDDHHMM format
' -- with LEADING ZEROS for consistency.
' -- because leading zeros are suppressed for single digit values returned, add 100
' -- to the value and truncate it to get the leading zeros.
' -- This datestamp is incorporated into the ISQL output file name.
strDate = Now
strYear = year(strDate)
strMonth = right(month(strDate) + 100,2)
strDay = right(day(strDate) + 100,2)
strHH = right(hour(strDate) + 100,2)
strMM = right(minute(strDate) + 100,2)
strDateStamp = strYear & strMonth & strDay & strHH & strMM
'---- Display all command-line parameters
'For I = 0 to objArgs.Count - 1
' Wscript.Echo "parm # " & I & ": " & objArgs(I)
'Next
'---- value local variables with the arguements from the objArgs object
'---- at least database name and script name are required
'---- if no arguements passed issue error message and non-zero return code
'if objArgs.Count > 0 Then
' strDbname = ObjArgs(0)
'else
' strText = "database name required " & CRLF & "exit code(99)"
' Wscript.Echo strText
' Wscript.Quit(99)
'end if
'if objArgs.Count > 1 Then
' strScriptName = ObjArgs(1)
'else
' strText = "script name required " & CRLF & "exit code(99)"
' Wscript.Echo strText
' Wscript.Quit(99)
'end if
'if objArgs.Count > 2 Then
' strForceZero = ObjArgs(2)
'else
' strForceZero = "no"
'end if
'if objArgs.Count > 3 Then
' strSQLPath = ObjArgs(3)
'else
strSQLPath = "k:\batch\SQL\"
'end if
'if objArgs.Count > 4 Then
' strText = "invalid parm - ignored "
' Wscript.Echo strText
'end if
strSQLScript = "C:\JIRA\Sweeps\vipin.sql"
strReportFile = "C:\JIRA\Sweeps\logfilevipin.txt"
strReportFile = "C:\JIRA\Sweeps\logfilevipin.xls"
strISQL = "sqlcmd /S idcsrv17 -U sa -P ldef /n /d" & "1015" & " /i" & strSQLScript & " /o" & strReportFile
Wscript.Echo strISQL
'---- Run ISQL
Set WshShell = Wscript.CreateObject("Wscript.Shell")
IntReturn = WshShell.Run(strISQL, 0, TRUE)
'Wscript.Echo "ISQL return code was " & IntReturn
if IntReturn > 0 Then
'Wscript.Echo "exit code(99)"
'Wscript.Quit(99)
End If
Wscript.Quit(0)