Print Page | Close Window

Access To SQL

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3846
Printed Date: 30 March 2026 at 5:00am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Access To SQL
Posted By: zaboss
Subject: Access To SQL
Date Posted: 26 June 2003 at 7:43am

I am in the middle of migrating an app from Access to SQL Server and I'm in a desperate need of some relevant articles on SQL queries differences between those. 

For instance:

 <% msql = "SELECT * FROM InnerMessages WHERE InnerMessages.DateRead is Null AND InnerMessages.To='"& Session("UserName") &"'"
Set RS1 = Server.CreateObject("ADODB.Recordset")
RS1.Open msql, MyConn, 1,3 %> works with acces,but returns the error:

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Incorrect syntax near the keyword 'To'.

on SQL Server. And there are several others...



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web



Replies:
Posted By: ljamal
Date Posted: 26 June 2003 at 8:45am
Sounds less like a SQL Server problem and more like there being nothing stored in the Session variable. If you print out the SQL statement I'm sure it looks like this:
SELECT * FROM InnerMessages WHERE InnerMessages.DateRead is Null AND InnerMessages.To=''

which SQL will not accept. To circumvent that just check the length of the session variable before placing it in the SQL statement.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: zaboss
Date Posted: 26 June 2003 at 10:40am
No, it's not that problem. The code works perfectly with access as it is.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: ljamal
Date Posted: 26 June 2003 at 11:12am
I may work with Access but SQL server will not search for '', it's either null or a value. Try inserting a value instead of the session variable and I assure you that SQL Server will not return the error.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Gullanian
Date Posted: 26 June 2003 at 11:13am

you will need to change the field called To to something else, IE messageTo, as To is a reserved keyword.



Posted By: zaboss
Date Posted: 26 June 2003 at 12:17pm

Nope, Gullanian, it is not that as I have a similar error somewhere else. And also, To is a reserved word for Access too, but on both you CAN use tablename.To... The problem is with that single quotes I'm sure as the problem appears in the sql queries that use them.

And ljamal, I know for sure that it triggers the session variable as i have on another page an Response.Write(Session("UserName")) whici is fine.



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: zaboss
Date Posted: 26 June 2003 at 12:40pm
Damn, Gullanian, you were right. Those field names should be in []!!!! Thanks man!

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: Gullanian
Date Posted: 26 June 2003 at 3:31pm
No problem hehe



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net