簡體   English   中英

需要有關SQL查詢SQLserver或Access的幫助

[英]Need help for SQL Query SQLserver or Access

我有一個數據網格:

在此處輸入圖片說明

我想列出logo=truechair=true還是color=true ,但name IS NOT NULL值。

我試過了:

SELECT 
    name,
    logo,
    chair,
    color 
FROM 
    Mytable 
WHERE 
    logo = True OR chair = True OR color = True 
    AND name IS NOT NULL

但是此查詢將列出所有列。

我知道查詢錯誤,但是找不到錯誤。

如何解決這個問題?

在此處發布我的完整代碼:

  Try
        Dim dt As New DataTable()
        Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & Application.StartupPath & "\db.mdb';")
        Dim cmd As New OleDbCommand("Select * from table WHERE (chair = 'true' or color = 'true' or logo = 'true') and name is not null", con)
        Dim adap As New OleDbDataAdapter(cmd)
        adap.Fill(dt)
        DataGridView1.DataSource = dt
        DataGridView1.Columns(0).HeaderText = "Name"
        DataGridView1.Columns(1).HeaderText = "Logo"
        DataGridView1.Columns(2).HeaderText = "Chair"
        DataGridView1.Columns(3).HeaderText = "Color"
        dt = Nothing
        con = Nothing
        cmd = Nothing
        adap = Nothing
    Catch ex As Exception

    End Try

對於SQL Server :嘗試將()放在OR的條件周圍,還需要在值True周圍放置'' ,如下所示:

Select 
  name,logo,chair,color 
From Mytable 
Where (logo = 'True' or chair = 'True' or color = 'True')
  And name Is Not Null;

這假定logochaircolor聲明為數據類型bit (布爾值)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM