pozitron969
Programmer
Hello,
I am trying to use the Replace Statement to clean up a portion of a SQL statement that I use.
Snippet:
The top 3 Replace statements in the second group work just fine, but the last one won't replace the WHERE AND text with WHERE
Resulting SQL Statement:
Error Message:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'AND'.
/datacenter/ftmidb_search.asp, line 125
From my testing & fiddling it seems like the replace won't work with a space in the first parameter. (which seems crazy to me) But if that is true then why are the other statements working just fine? I have tried rewriting the statement thinking that i have an escape code in there somewhere and it still behaves that way.
Many Thanks in advanced.
Andy
I am trying to use the Replace Statement to clean up a portion of a SQL statement that I use.
Snippet:
Code:
sSQL = "SELECT dbo.FTMILog.Time,dbo.FTMILog.Message, dbo.FTMILog.LogLevel FROM dbo.FTMILog WHERE dbo.FTMILog.Message LIKE '[sMess]' AND dbo.FTMILog.Time > '[sFromDate]' AND dbo.FTMILog.Time < '[sToDate]' AND ([sErrLev])"
'// No input then set to Default Behaviour
if Len(sErrLev) < 1 then
'// Default Behaviour is to return all message flag types
sErrLev = "dbo.FTMILog.LogLevel LIKE 'I' OR dbo.FTMILog.LogLevel LIKE 'N' OR dbo.FTMILog.LogLevel LIKE 'W' OR dbo.FTMILog.LogLevel LIKE 'E'"
'//Temporarily only return Errors
sErrLev = "dbo.FTMILog.LogLevel LIKE 'E'"
end if
sSQL = Replace(sSQL,"[sMess]",sMsgSearch) 'Works fine
sSQL = Replace(sSQL,"[sFromDate]",sFromDate) 'Works fine
sSQL = Replace(sSQL,"[sToDate]",sToDate) 'Works fine
sSQL = Replace(sSQL,"[sErrLev]",sErrLev) 'Works fine
sSQL = Replace(sSQL,"dbo.FTMILog.Message LIKE ''","") 'Works fine
sSQL = Replace(sSQL,"AND dbo.FTMILog.Time > ''","") 'Works fine
sSQL = Replace(sSQL,"AND dbo.FTMILog.Time < ''","") 'Works fine
sSQL = Replace(sSQL,"WHERE AND","WHERE") 'Doesn't Work
response.write sSQL
Set rs =Server.CreateObject("ADODB.Recordset")
rs.open sSQL, conn
The top 3 Replace statements in the second group work just fine, but the last one won't replace the WHERE AND text with WHERE
Resulting SQL Statement:
Code:
SELECT dbo.FTMILog.Time,dbo.FTMILog.Message, dbo.FTMILog.LogLevel FROM dbo.FTMILog WHERE AND (dbo.FTMILog.LogLevel LIKE 'E')
Error Message:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'AND'.
/datacenter/ftmidb_search.asp, line 125
From my testing & fiddling it seems like the replace won't work with a space in the first parameter. (which seems crazy to me) But if that is true then why are the other statements working just fine? I have tried rewriting the statement thinking that i have an escape code in there somewhere and it still behaves that way.
Many Thanks in advanced.
Andy