一张表多条件查询( 续--简洁)

来源:互联网 发布:360所有软件都有啥 编辑:程序博客网 时间:2024/05/22 00:41


 Dim strsql As String = ""

            ‘//因为winform 不像web那样, 如下显示绑定后的字段定义名称更简洁
            strsql = "select code as 代碼, name  as 交易名稱, addornot as 操作庫存,status as 狀態,codegroup 組別  from stor_tradecode  where 1=1 "

            If txtquery1.Text.Length > 0 Then
                strsql += " and code ='" + txtquery1.Text + "' "
            End If


            If txtquery2.Text.Length > 0 Then
                strsql += " and name like '" + txtquery2.Text + "%' "
            End If





 Dim sql As String
 Dim whereCondition As String = ""


            If Me.BoNum.Text.Length > 0 Then
                whereCondition = " and a.BoNum like '%" & Me.BoNum.Text & "%'"
            End If


            If Me.PoNum.Text.Length > 0 Then
                whereCondition = " and  g.PoNum = '" & Me.PoNum.Text & "' "
            End If


            If Me.cbStartDate1.Checked = True And Me.cbEndDate1.Checked = False Then
                whereCondition += " and Convert(varchar(10),OperateDate,21)='" & Format(Me.StartDate1.Value, "yyyy-MM-dd") & "'"
            ElseIf Me.cbStartDate1.Checked = False And Me.cbEndDate1.Checked = True Then
                whereCondition += " and Convert(varchar(10),OperateDate,21)='" & Format(Me.EndDate1.Value, "yyyy-MM-dd") & "'"
            ElseIf Me.cbStartDate1.Checked = True And Me.cbEndDate1.Checked = True Then
                whereCondition += " and Convert(varchar(10),OperateDate,21) between '" & Format(Me.StartDate1.Value, "yyyy-MM-dd") & "' and '" & Format(Me.EndDate1.Value, "yyyy-MM-dd") & "'"
            End If


           sql = "select Distinct(a.BoNum),b.TradeType,c.InOrOutType,d.ToStore,e.FromStore,a.StorePlace,a.DeliverNo,a.DeliverPerson,a.DeliverDate,a.DeliverCar,a.Batch,BoStatus=f.ListA,"
            sql += "a.Remark,a.OperatePerson,a.OperateDate,a.CheckPerson,a.CheckDate,'' as PoNum,h.Date  from Stor_TradeMaster a left join "
            sql += " (select a.BoNum,b.name as TradeType from Stor_TradeMaster a inner join Stor_tradecode b on a.TradeType=b.AddorNot where b.code='01') b on a.BoNum=b.BoNum left join "
             ……
            sql += "left join Stor_TradeDetail g on a.BoNum = g.BoNum left join Pur_POA h on g.Ponum = h.Num"
            sql += " where f.ItemNo=16 and a.TradeType='+'" & whereCondition




         3

         Try
            Dim sql As String = String.Empty
            sql = "select * from Sys_Language where 1=1 "
            If Me.TxtmoduleQ.Text.Length > 0 Then
                sql &= "  and SysModule='" + Me.TxtmoduleQ.Text + "'" & vbCrLf
            End If
            If Me.TxtobjectQ.Text.Length > 0 Then
                sql &= "  and Sysobject='" + Me.TxtobjectQ.Text + "'" & vbCrLf
            End If
            Dim Rst As DataSet = New DataSet
            Rst = ReturnDataset(sql)
            Me.DGV_language.DataSource = Rst.Tables(0)
        Catch ex As Exception
            MsgBox("Err: BtnFind_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try

原创粉丝点击