G
Guest
I have the following sql statement that I want to put into a string sql.
With all the DoubleQuotes, I have tried """ & "h" & """ for instance to put
a "h" into the format statement and somewhere in the sql so the statement is
an absolute monster to follow.
When I dumped the string into a msg box before trying to set the recordset
to the string, it seems to show all the right quotes so I'm not sure where
the error is.
Can someone explain the syntax of how to add quotes into a sqlstring?
Thanks
Here is the Raw Query:
TRANSFORM Count(Hour([tblCallLog]![LogTime])) AS Expr1
SELECT DatePart("h",[LogTime]) AS [Order], Format(([LogTime]),"h am/pm") AS
Hours
FROM tblContactType INNER JOIN (tblBuyers INNER JOIN tblCallLog ON
tblBuyers.BuyerID = tblCallLog.BuyerID) ON tblContactType.ContactTypeID =
tblCallLog.CallType
WHERE (((tblBuyers.ShortName)="Tony") AND ((tblBuyers.BuyerFilter)=True) AND
((tblContactType.BuyerAtDesk)="Yes"))
GROUP BY DatePart("h",[LogTime]), Format(([LogTime]),"h am/pm"),
tblBuyers.BuyerFilter, tblContactType.BuyerAtDesk, tblBuyers.ShortName
ORDER BY DatePart("h",[LogTime]), Format(([LogDate]),"w")-1 & ": " &
Format(([LogDate]),"ddd")
PIVOT Format(([LogDate]),"w")-1 & ": " & Format(([LogDate]),"ddd");
Here is my modified sqlstring:
strQry = "TRANSFORM Count(Hour([tblCallLog]![LogTime])) AS Expr1" _
& "SELECT DatePart(""" & "h" & """,[LogTime]) AS [Order],
Format(([LogTime]),""" & "h am/pm" & """) AS Hours" _
& "FROM tblContactType INNER JOIN (tblBuyers INNER JOIN tblCallLog ON
tblBuyers.BuyerID = tblCallLog.BuyerID) ON tblContactType.ContactTypeID =
tblCallLog.CallType" _
& "WHERE (((tblBuyers.ShortName) = """ & "Tony" & """) And
((tblBuyers.BuyerFilter) = True) And ((tblContactType.BuyerAtDesk) = """ &
"Yes" & """))" _
& "GROUP BY DatePart(""" & "h" & """,[LogTime]), Format(([LogTime]),""" & "h
am/pm" & """), tblBuyers.BuyerFilter, tblContactType.BuyerAtDesk,
tblBuyers.ShortName" _
& "ORDER BY DatePart(""" & "h" & """,[LogTime]), Format(([LogDate]),""" &
"w" & """)& Format(([LogDate]),""" & "ddd" & """)" _
& "PIVOT Format(([LogDate]),""" & "w" & """)-1 & Format(([LogDate]),""" &
"ddd" & """);"
With all the DoubleQuotes, I have tried """ & "h" & """ for instance to put
a "h" into the format statement and somewhere in the sql so the statement is
an absolute monster to follow.
When I dumped the string into a msg box before trying to set the recordset
to the string, it seems to show all the right quotes so I'm not sure where
the error is.
Can someone explain the syntax of how to add quotes into a sqlstring?
Thanks
Here is the Raw Query:
TRANSFORM Count(Hour([tblCallLog]![LogTime])) AS Expr1
SELECT DatePart("h",[LogTime]) AS [Order], Format(([LogTime]),"h am/pm") AS
Hours
FROM tblContactType INNER JOIN (tblBuyers INNER JOIN tblCallLog ON
tblBuyers.BuyerID = tblCallLog.BuyerID) ON tblContactType.ContactTypeID =
tblCallLog.CallType
WHERE (((tblBuyers.ShortName)="Tony") AND ((tblBuyers.BuyerFilter)=True) AND
((tblContactType.BuyerAtDesk)="Yes"))
GROUP BY DatePart("h",[LogTime]), Format(([LogTime]),"h am/pm"),
tblBuyers.BuyerFilter, tblContactType.BuyerAtDesk, tblBuyers.ShortName
ORDER BY DatePart("h",[LogTime]), Format(([LogDate]),"w")-1 & ": " &
Format(([LogDate]),"ddd")
PIVOT Format(([LogDate]),"w")-1 & ": " & Format(([LogDate]),"ddd");
Here is my modified sqlstring:
strQry = "TRANSFORM Count(Hour([tblCallLog]![LogTime])) AS Expr1" _
& "SELECT DatePart(""" & "h" & """,[LogTime]) AS [Order],
Format(([LogTime]),""" & "h am/pm" & """) AS Hours" _
& "FROM tblContactType INNER JOIN (tblBuyers INNER JOIN tblCallLog ON
tblBuyers.BuyerID = tblCallLog.BuyerID) ON tblContactType.ContactTypeID =
tblCallLog.CallType" _
& "WHERE (((tblBuyers.ShortName) = """ & "Tony" & """) And
((tblBuyers.BuyerFilter) = True) And ((tblContactType.BuyerAtDesk) = """ &
"Yes" & """))" _
& "GROUP BY DatePart(""" & "h" & """,[LogTime]), Format(([LogTime]),""" & "h
am/pm" & """), tblBuyers.BuyerFilter, tblContactType.BuyerAtDesk,
tblBuyers.ShortName" _
& "ORDER BY DatePart(""" & "h" & """,[LogTime]), Format(([LogDate]),""" &
"w" & """)& Format(([LogDate]),""" & "ddd" & """)" _
& "PIVOT Format(([LogDate]),""" & "w" & """)-1 & Format(([LogDate]),""" &
"ddd" & """);"