tags:

views:

54

answers:

2

In Access Sql 1 or 2 returns -1 the value for true. How can i get it to return 3 which is the numeric orring (?) of the values. This works in Sql Server

select 1 | 2

returns 3

+2  A: 

Try BOR maybe that will work, http://www.pcreview.co.uk/forums/thread-1177792.php

CRice
A: 

Just to add to CRice answer, BOR is what is required here.

Here's a repro using Jet 4.0, its OLE DB provider and ADO in VBA code:

Sub TestBOR()

  On Error Resume Next
  Kill Environ$("temp") & "\DropMe.mdb"
  On Error GoTo 0

  Dim cat
  Set cat = CreateObject("ADOX.Catalog")
  With cat
    .Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & _
        Environ$("temp") & "\DropMe.mdb"
    With .ActiveConnection

      Dim Sql As String
      Sql = "SELECT 1 BOR 2;"
      .Execute Sql
      Dim rs
      Set rs = .Execute(Sql)
      MsgBox rs.GetString
    End With
    Set .ActiveConnection = Nothing
  End With
End Sub

The result is 3, as expected.

If you want to do this using the Access UI you need to ensure it is in ANSI-92 Query Mode. If you want to do this using DAO... you can't! DAO always uses ANSI-89 Query Mode. Use ADO because it always uses ANSI-92 Query Mode. Happily, you can mix ADO code with DAO code in the same project.

onedaywhen
BTW, is there something about XOR that wouldn't be appropriate here? The help file says "The Xor operator performs as both a logical and bitwise operator" and it works in SQL 89 mode. I don't know what's expected from BOR, so can't tell if it's 100% equivalent.
David-W-Fenton
OK, just did some testing and don't know what to think. 1 XOR 2 returns 3 in the Immediate window in the VBE, but returns 0 in a SELECT statement. It would appear that BOR is the only one that produces the expected result in SQL, unless I'm doing something wrong.
David-W-Fenton
You can use ADO without needing a reference, either via late binding, or by using the CurrentProject.Connection object as your top-level object, and use object variables for your recordset and so forth.
David-W-Fenton
@David-W-Fenton: "You can use ADO without needing a reference... via late binding" -- you are preaching to the converted: my code uses late binding.
onedaywhen
@David-W-Fenton: "using the CurrentProject.Connection object" -- my experience tells me that use of the vernacular "Access sql" does not always mean the OP has the Access UI installed... but feel free to add the equivalent code to my answer if you think it will add value.
onedaywhen
I think the comments make this clearer than editing it into your answer which, as you say, used late binding all along (as well as not typing variables, so could be used in vbScript, not just VBA).
David-W-Fenton