如何为以下场景编写sqlite查询?

时间:2013-11-13 04:46:18

标签: sql sqlite reportviewer

这是我对wpf表单的查询

Query = "select Cust_Id,Card_Number,Clients_Title,Address_Current,Phone_Number,Mobile_Number from Customer_New Where 1=1";
try
{
    if (txt_title.Text != "")
        Query += " and Clients_Title Like '%" + txt_title.Text + "%'";
    if (txt_address.Text != "")
        Query += " and Address_Current Like '%" + txt_address.Text + "%'";
    if (txt_phone.Text != "")
        Query += " and Phone_Number Like '%" + txt_phone.Text + "%'";
    if (txt_mobile.Text != "")
        Query += " and Mobile_Number Like '%" + txt_mobile.Text + "%'";
    if (cbo_location.Text != "")
        Query += " and AreaLocation Like '%" + cbo_location.Text + "%'";
}

catch { }

我想报告查看器查询数据,例如我的wpf表单。 这是我在报表查看器中尝试的查询

SELECT        Cust_Id, Clients_Title, Card_Number, Key_Person, Address_Current, Phone_Number, Mobile_Number, AreaLocation
FROM            Customer_New
WHERE        (Clients_Title = @Clients_Title) OR
                         (Address_Current = @Address_Current) OR
                         (Phone_Number = @Phone_Number) OR
                         (Mobile_Number = @Mobile_Number) OR
                         (AreaLocation = @AreaLocation) 

任何人都可以告诉我查询报告查看器,如wpf表单。 注意: -

  1. 我无法在报表查看器中使用C#控件。这是报表 查看器我只能使用sql
  2. 报告查看器查询需要:

    • 何时所有where子句的字符串都为null,那么我的报表查看器为 应该选择查询是:

      Query =“从Customer_New中选择Cust_Id,Card_Number,Clients_Title,Address_Current,Phone_Number,Mobile_Number”;

    • 当任何两个where子句的字符串不匹配时 行数据库然后没有

    将显示

    • 最后,如果只是where子句的一个条件,将进行选择 已提供

1 个答案:

答案 0 :(得分:0)

SELECT        Cust_Id, Clients_Title, Card_Number, Key_Person, Address_Current, Phone_Number, Mobile_Number, AreaLocation
FROM            Customer_New
    where        (CASE
        WHEN @Clients_Title != ''   THEN Clients_Title=@Clients_Title
      ELSE
         NULL IS NULL
      END)
      AND(CASE
        WHEN @Address_Current != '' THEN Address_Current =@Address_Current
      ELSE
         NULL IS NULL
      END)
              AND(CASE
        WHEN @Phone_Number != '' THEN Phone_Number=@Phone_Number
      ELSE
         NULL IS NULL
      END)
      AND(CASE
        WHEN @Mobile_Number != '' THEN Mobile_Number=@Mobile_Number
      ELSE
         NULL IS NULL
      END)
      AND(CASE
        WHEN @AreaLocation != '' THEN AreaLocation =@AreaLocation
      ELSE
         NULL IS NULL
      END) 
相关问题