sql querry not working ?

  • hi !!

    following SQL query is not working on SQL Server

    "Select * from myTable Where True"

    this query gives error "Incorrect syntax near 'True'" on SQLServer

    but on MS Access this query works without error !!

    Pl. help me out

    SPD

  • hi ,

    what is true ??

    Select * from mytable where willi = true

    This true must be an char in the row.

    What stand in the table please

    Thomas

  • in my project I am building up a SQL query according to multiple controls on the form

    Dim strSQL As String

    strSQL = "SELECT this, that, theother FROM mytable WHERE TRUE"

    which will (initially) return all records.

    the code then step through the controls on the form; if the

    control contains anything ...

    strSQL = strSQL & " AND [fieldname] = '" & Me!controlname & "'"

    to the growing SQL string. If the control is empty, just leave strSQL

    alone.

    this code works on MS Access , but on SQL Server I am getting error

    "Incorrect syntax near 'True'"

    pl. suggest some sol on this prob.

    thanx

    SPD

  • Sorry i dont understand your Problem .

    Is true an Row ??

    So i think you do this:

    Dim strSQL As String

    strSQL = "SELECT this, that, theother FROM mytable WHERE "

    strSQL = strSQL & " [fieldname] = '" & Me!controlname & "'"

    But why you dont do it in one way??

    if Me!controlname "" then

    dim strSQL as String =

    Dim strSQL As String

    strSQL = "SELECT this, that, theother FROM mytable WHERE [fieldname] = '" & Me!controlname & "'"

    else

    strSQL = "SELECT this, that, theother FROM mytable"

    end if

    or by your way:

    Dim strSQL As String

    if Me!controlname "" then

    strSQL = "SELECT this, that, theother FROM mytable where [fieldname] = '" & Me!controlname & "'"

    Else

    strSQL = "SELECT this, that, theother FROM mytable"

    end if

    Greetings Thomas

  • thanx for suggestions.

    but I got solution for my Prob.

    I rewrite query as "SELECT this, that, theother FROM mytable Where 1=1"

    thanx once again

    SPD

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply