简体   繁体   中英

SQL statement that works for MS Access and SQL Server

I have a web application that is using a Microsoft Access database as well as Microsoft SQL Server. Basically I am trying to eventually move the data from Access to SQL Server and want to write an inline SQL query that will retrieve the same bit value for both Access and SQL Server so when the conversion is made the incline code doesn't need to be changed.

MS Access allows you to set bit values = true whereas SQL Server requires you to have this same true value in single quotes when accessing its value (='true'). SQL Server allows you to use 0 and 1 as values to check against bits but Access doesn't.

Is it possible to write one SQL statement that returns the same values from both databases?

Microsoft Access and SQL server both set bit values false as 0 so you can write a select statement like this to return false

            SELECT * FROM Assets WHERE Active = 0 

and another statement like this to return true values

            SELECT * FROM Assets WHERE NOT Active = 0

this will allow you to have one SQL statement that works for both databases as you convert your application from an Access database to a SQL Server database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM