SQL - query True or False records

Asked

Viewed 501 times

1

I am mounting a simple page that show records marked as blocked by admin. The field is user-block and the options are FALSE or TRUE.

I thought the Query would be:

"Select * from Usuarios WHERE user-block = "&TRUE&" order by NOME asc"

But this select returns missing parameter error

Can anyone explain to me what’s wrong with the instruction?

  • is ASP VB Script with Access Database?

  • Yes, Virgilio. That’s right.

  • Take a look at my answer yours is functional, but has problems with performances.

2 answers

1

The right in your would be:

Select * from Usuarios WHERE [user-block]=true order by NOME asc

simply because of the dash (-) you have to put clasps ([ and ]), and it wouldn’t be very nice to do so, try to put the fields with underscore, that is, trace down example user_block, but, it would solve your doubt.

Complete code

<%

    dim connection
    dim result

    set connection = Server.CreateObject("ADODB.Connection")
    set result = Server.CreateObject("ADODB.recordset")

    connection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\adm.mdb"


    result.Open "SELECT * FROM Usuarios WHERE [user-block]=true", connection



    Do While Not result.EOF
        Response.Write(result.Fields("Id") & " - ")
        Response.Write(result.Fields("Nome") & " - ")
        Response.Write(result.Fields("user-block"))
        Response.Write("<br />")

        result.MoveNext
    Loop

    connection.Close
    set connection = Nothing
%>

References:

0

Problem solved. Just filter the records after selecting them:

sSQL = "Select * from Usuarios order by nome asc"       

set RStemp = createobject("adodb.recordset")
set RStemp.activeconnection = usersDB

regs = 10
pag = 1

RStemp.cursortype = 3
RStemp.pagesize = regs
RStemp.open sSQL
TotalInscritos = RStemp.RecordCount
RStemp.filter = "user-block = TRUE"

I hope the solution will be useful to others

  • It would not be ideal, because it ends up bringing everything that has in its database, and then make a filter, it is better to come already filtered, this brings bad performance. In my answer the solution to a certain field.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.