I am getting an eror on my SQL query string as shown below and I'm not
sure why the syntax is wrong....
ERROR: Microsoft OLE DB Provider for SQL Server: Line 12: Incorrect
syntax near 'item'
CODE:
Str_Connect = "Provider=SQLOLEDB;Data
Source=SQLSERVER;Trusted_Connection=Yes;Initial Catalog=assystDev2"
Set CnnSQL=CreateObject("ADODB.Connection")
CnnSQL.Open Str_Connect
If CnnSQL.State=1 Then
Wscript.Echo "Connected"
else
Wscript.Echo "Not Connected"
End If
Set Rs=CreateObject("ADODB.Recordset")
' ********** This is the line that produces the ERROR
***********
Set Rs=CnnSQL.Execute("SELECT item.item_n, item.expiry_date,
usr.email_add" & _
" FROM assyst.dbo.item item INNER JOIN assyst.dbo.usr usr" & _
"ON item.usr_id=usr.usr_id" & _
" WHERE (item.expiry_date>=(ts '2008-01-01 00:00:00') AND
item.expiry_date<(ts '2008-03-01 00:00:01'))")
Do while not Rs.EOF
Wscript.Echo (Rs(0) & space(3) & Rs(1) & space(3) & Rs(2) & space(3) &
Rs(3))
Rs.MoveNext
Loop
OVERVIEW: I need to run a daily report of contract expirations for
the next month and email the contract holder with that information.
This is being done manually using the following query:
SELECT "item"."item_n", "item"."expiry_date", "usr"."email_add"
FROM "assyst"."dbo"."item" "item" INNER JOIN "assyst"."dbo"."usr"
"usr" ON "item"."usr_id"="usr"."usr_id"
WHERE ("item"."expiry_date">={ts '2008-01-01 00:00:00'} AND
"item"."expiry_date"<{ts '2008-03-01 00:00:01'})
It returns the following:
Item_n expiry_date email_add
I have noticed that some of the records returned have some blank
(null?) data .
I also want to replace the hard coded dates with today and (today
+30) dates.
Thanks for your help!