gunZ333
gunZ333

Reputation: 61

SQL Query, incorrect syntax near "keyword"

could you help me, in finding the error in my query, i'm taking hours in solving this error, thanks in advance

sqlquery = "SELECT dbo.trans_queue.que_no, dbo.trans_step.step_remarks," _
                & " dbo.office.office_name, dbo.transaction.trans_name," _
                & " dbo.trans_queue.date_arrive, dbo.trans_queue.time_arrive" _
                & " FROM dbo.trans_queue" _
                & " INNER JOIN dbo.trans_step ON dbo.trans_queue.trans_step_Id = dbo.trans_step.trans_step_Id" _
                & " INNER JOIN dbo.office ON dbo.trans_queue.office_Id = dbo.office.office_Id" _
                & " INNER JOIN dbo.transaction ON dbo.trans_queue.trans_Id = dbo.transaction.trans_Id" _
                & " WHERE dbo.office.office_Id = '" & Now_Office_ID & "'" _
                & " ORDER BY dbo.trans_queue.time_arrive AND dbo.trans_queue.date_arrive"

the error always telling me that "incorrect syntax near 'transaction'"

Upvotes: 0

Views: 1356

Answers (2)

Abiezer
Abiezer

Reputation: 782

Your error should be using the researved word "transaction" you dont specify your Database, in Microsoft SQL SERVER you should use :

dbo.[transaction].trans_name,

Upvotes: 0

xtoik
xtoik

Reputation: 676

Most probably the problem comes from the fact that your table name TRANSACTION is a reserved word in Transact SQL. Replace all the occurrences of transaction in your query by the word between square brackets:

sqlquery = "SELECT dbo.trans_queue.que_no, dbo.trans_step.step_remarks," _
            & " dbo.office.office_name, dbo.[transaction].trans_name," _
            & " dbo.trans_queue.date_arrive, dbo.trans_queue.time_arrive" _
            & " FROM dbo.trans_queue" _
            & " INNER JOIN dbo.trans_step ON dbo.trans_queue.trans_step_Id = dbo.trans_step.trans_step_Id" _
            & " INNER JOIN dbo.office ON dbo.trans_queue.office_Id = dbo.office.office_Id" _
            & " INNER JOIN dbo.[transaction] ON dbo.trans_queue.trans_Id = dbo.[transaction].trans_Id" _
            & " WHERE dbo.office.office_Id = '" & Now_Office_ID & "'" _
            & " ORDER BY dbo.trans_queue.time_arrive AND dbo.trans_queue.date_arrive"

Upvotes: 3

Related Questions