MS Access Project uses incorrect SQL if RecordSource starts with leading space.

I had a MS Access 2002 VB code

Form.RecordSource = " Select * from dbo.[TempBarcodesList]  where SessionID= " & Quoted(hdnSessionID)

with a leading space before Select in SQL statement.

Profiler showed that the following SQL was send to the database 

 exec sp_executesql N'SELECT * FROM   Select * from dbo.[TempBarcodesList]  where SessionID= ''2006-02-22 12:07:06.327''  WHERE "SessionId" = @P1 AND "AutoID" = @P2', N'@P1 varchar(23),@P2 bigint', '2006-02-22 12:07:06.327', 22 

and it obviosly had sintax errors.

When the leading space  was remove access inserted brackets and generated SQL became correct:

exec sp_executesql N'SELECT * FROM ( Select * from dbo.[TempBarcodesList]  where SessionID= ''2006-02-22 11:49:48.043'' ) AS DRVD_TBL WHERE "SessionId" = @P1 AND "AutoID" = @P2', N'@P1 varchar(23),@P2 bigint', '2006-02-22 11:49:48.043', 12 

 

 

posted @ Wednesday, February 22, 2006 8:36 AM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 1 and type the answer here:
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011