In Microsoft Access, you can say:
SELECT columns FROM table WHERE boolColumn=TRUE -- or SELECT columns FROM table WHERE boolColumn=FALSE |
Unfortunately, this doesn't work in SQL Server. The following can be used in SQL Server:
SELECT columns FROM table WHERE bitColumn=1 -- or SELECT columns FROM table WHERE bitColumn=0 |
However, this doesn't work in Access, since TRUE in Access is -1, not 1. Confused yet? :-)
For cross-platform support, use the following queries:
SELECT columns FROM table WHERE bitColumn<>0 -- or SELECT columns FROM table WHERE bitColumn=0 -- to update (Access will convert to -1): UPDATE table SET bitColumn=1 --or UPDATE table SET bitColumn=0 |
Also, remember that if you're using checkboxes to update / insert / display data, you have to convert from "on" or "" to 1 or 0, and when retrieving you must change 1 or 0 (or true or false) to "checked"... for example, page1.asp:
<form method=post action=page2.asp> <input type=checkbox name=bool> <input type=submit> </form> |
And page2.asp:
<% bitValue = 0 bool = request.form("bool") if bool = "on" then bitValue=1 sql = "UPDATE table SET bitColumn=" & bitValue ' ... %> |
And page3.asp:
<% set conn = CreateObject("ADODB.Connection") conn.open "<connection string>" set rs = conn.execute("SELECT bitColumn FROM table") ch="" bitValue = rs(0) if bitValue then ch=" CHECKED" ' or you could say if bitValue<>0 then ch=" CHECKED" %> <form method=post action=page2.asp> <input type=checkbox name=bool <%=checked%>> <input type=submit> </form> |