Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test a SQL Statement in Query Analyzer

Status
Not open for further replies.

debbie1212

Programmer
May 31, 2000
66
US
Can I test a SQL statement in Query Analyzer without passing in the parameters? In other words, I have the following statement in my class and I want to find out what it is passing:

Public Sub UpdateAEtProjectSchedule(sConnectString , rsAEtProjectSchedule , RC , ErrorMessage )

sSQLStmt = ""
sSQLStmt = sSQLStmt & "execute AEstoUpdateAEtProjectSchedule "
sSQLStmt = sSQLStmt & "@schdkey=" & rsAEtProjectSchedule.Fields.Item("SchdKey") & ","
sSQLStmt = sSQLStmt & "@schdprojkey=" & rsAEtProjectSchedule.Fields.Item("SchdProjKey") & ","
sSQLStmt = sSQLStmt & "@schdphase=" & Replace(RTrim(rsAEtProjectSchedule.Fields.Item("SchdPhase")), "'", "''") & ","
sSQLStmt = sSQLStmt & "@schdduration=" & rsAEtProjectSchedule.Fields.Item("SchdDuration") & ","
sSQLStmt = sSQLStmt & "@schdstartdate=" & sDateFormat(rsAEtProjectSchedule.Fields.Item("SchdStartDate")) & ","
sSQLStmt = sSQLStmt & "@schdenddate=" & sDateFormat(rsAEtProjectSchedule.Fields.Item("SchdEndDate"))

I have the following code in my ASP page:

rsAEtProjectSchedule.Fields("SchdProjKey") = sKey
For nSub = 1 to ubound(sPhase)
rsAEtProjectSchedule.Fields("SchdPhase") = sPhase(nSub)
rsAEtProjectSchedule.Fields("SchdDuration") = sPhaseDuration(nSub)
rsAEtProjectSchedule.Fields("SchdStartDate") = sPhaseStart(nSub)
rsAEtProjectSchedule.Fields("SchdEndDate") = sPhaseEnd(nSub)
objProjectSchedule.UpdateAEtProjectSchedule Session("DATA_SOURCE"), rsAEtProjectSchedule, RC, ErrorMessage
If RC = rsReturnCodes.Fields("RC_SUCCESS") Then
Else
sResult = "Error encountered on Schedule Update. " & ErrorMessage
tfContinue = False
Exit For
End If
Next

I get the error message "Error encountered on Schedule Update. Line 1: Incorrect syntax near ','.

I would like to test it in the Query Analyzer to see what it is passing. I tried testing it in the web page with a Response.Write which was suggested on another thread but it didn't work right. I must have put it in the wrong place.

I know the problem is with schdPhase because of all of the quotes and commas but I need to see what exactly it is passing to correct it.

Thanks,
Debbie
 
Put a response.write right after you have built the "sSQLStmt" string.

 
I already tried that and got the same error message. This is what I put:

sSQLStmt = ""
sSQLStmt = sSQLStmt & "execute AEstoUpdateAEtProjectSchedule "
sSQLStmt = sSQLStmt & "@schdkey=" & rsAEtProjectSchedule.Fields.Item("SchdKey") & ","
sSQLStmt = sSQLStmt & "@schdprojkey=" & rsAEtProjectSchedule.Fields.Item("SchdProjKey") & ","
sSQLStmt = sSQLStmt & "@schdphase='" & Replace(RTrim(rsAEtProjectSchedule.Fields.Item("SchdPhase")), "'", "''") & "'" & ","
sSQLStmt = sSQLStmt & "@schdduration=" & rsAEtProjectSchedule.Fields.Item("SchdDuration") & ","
sSQLStmt = sSQLStmt & "@schdstartdate=" & sDateFormat(rsAEtProjectSchedule.Fields.Item("SchdStartDate")) & ","
sSQLStmt = sSQLStmt & "@schdenddate=" & sDateFormat(rsAEtProjectSchedule.Fields.Item("SchdEndDate"))

Response.Write (&quot;SQL = &quot; & sSQLStmt & &quot;<br>&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top