| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 678 人关注过本帖
标题:多条件不定查询转换为存贮过程怎么弄啊
只看楼主 加入收藏
growingbird
Rank: 1
等 级:新手上路
帖 子:68
专家分:5
注 册:2008-12-24
结帖率:0
收藏
 问题点数:0 回复次数:7 
多条件不定查询转换为存贮过程怎么弄啊
大哥们能帮个忙吗
/////////////////////////////////////分割线//////////////////////////////

string strConn = " server=" + passname.dataip + "; database=MYERP;uid='sa';pwd='sa'";

                SqlConnection conn = new SqlConnection(strConn);

              conn.Open();

                string sqlsel = "select * from sickinfo where 0=0";

               
                ////////*************条件判断*********

               if (iskeyword.Text != "")
                {
                  sqlsel += " and askedinfo like '" + "%" + "" + iskeyword.Text.Trim() + "" + "%" + "' ";
               
                }

                if (iskf.Text != "")
                {
                  sqlsel += "and kefu='" + iskf.Text.Trim() + "'";
              
              }

                if (isdy.Text != "")
               {
                   sqlsel += "and admit='" + isdy.Text.Trim() + "' or kefu='" + isdy.Text.Trim() + "' ";
              
                }
                if (iszj.Text != "")
                {
                 sqlsel += "and zhuanjia='" + iszj.Text.Trim() + "'";
            
                }
                if (comboBox1.Text != "" && comboBox2.Text != "")
                {
                 sqlsel += "and addtime between '" + comboBox1.Text.Trim() + "' and '" + comboBox2.Text.Trim() + "'";
              
                }
              
                if (iszt.Text != "")
                {
                sqlsel += "and state ='" + iszt.Text.Trim() + "'";
              
                }
                if (islx.Text != "")
                {
                sqlsel += "and istype='" + islx.Text.Trim() + "'";
              
                }
                if (isly.Text != "")
                {
                  sqlsel += "and infofrom ='" + isly.Text.Trim() + "'";
            
                }

                SqlDataAdapter sda = new SqlDataAdapter(sqlsel, conn);
   

                sda.Fill(ds, "ds");
               
                conn.Close();
///////////////////////////////////////////////////到此//////////////////////

这个搜索怎么改成 存储过程啊
搜索更多相关主题的帖子: 分割线 
2010-12-24 14:02
kevintang
Rank: 4
等 级:业余侠客
威 望:9
帖 子:799
专家分:236
注 册:2008-2-14
收藏
得分:0 
ALTER PROCEDURE[dbo].[Wms_pProject_GetByCriteria]
    -- Add the parameters for the stored procedure here
    @IsFullSearch bit = null,
    @ProjectNo nvarchar(50) = null,
    @CustomerId bigint = null,
    @ProjectTypeId bigint=null,
    @StartDate datetime = null,
    @EndDate datetime = null,
    @StatusId bigint=null,
    @BranchId bigint=null,
    @OrderBy nvarchar(max) = null
 AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    DECLARE @sql       nvarchar(max),
            @sSymbol   nvarchar(max),
            @paramlist nvarchar(max);

    SELECT @sql =
        +'     SELECT     t1.*, '
        +' t2.Timestamp AS ProjectTypeTimestamp, t2.Name as ProjectTypeName, '
        +' t3.Name AS ProjectStatusName ,'
        +' t4.Code as CustomerCode, t4.Name AS CustomerName, t4.Timestamp AS CustomerTimestamp,'
        +' t5.Uid as CreatedByUserUid,'
        +' t6.Uid as UpdatedByUserUid,'
        +' t7.Name AS CreatedByStaffName, t7.IC AS CreatedByStaffIC,t7.EmployeeNo AS CreatedByStaffEmployeeNo,'
        +' t8.Name AS UpdatedByStaffName, t8.IC AS UpdatedByStaffIC,t8.EmployeeNo as UpdatedByStaffEmployeeNo,'
        +' t9.Name as BranchName,t9.Code as BranchCode'
        +' FROM         Wms_tProject t1 '
        +' INNER JOIN Wms_tProjectType t2 ON t1.ProjectTypeId = t2.Id '
        +' INNER JOIN Wms_tProjectStatus t3 ON t1.StatusId = t3.Id '
        +' INNER JOIN Master_tCompany t4 ON t1.CustomerId = t4.Id '
        +' INNER JOIN dbo.Auth_tUser AS t5 ON t1.CreatedByUserId = t5.Id '
        +' INNER JOIN dbo.Auth_tUser AS t6 ON t1.UpdatedByUserId = t6.Id '
        +' left outer  JOIN dbo.Master_tStaff AS t7 ON t1.CreatedByStaffId = t7.Id '
        +' left outer  JOIN dbo.Master_tStaff AS t8 ON t1.UpdatedByStaffId = t8.Id '
        +' inner join  Master_tCompany t9 ON t1.BranchId = t9.Id '
        +' WHERE 1=1 '

    IF @IsFullSearch IS NOT NULL
    BEGIN
        IF @IsFullSearch = 1
        BEGIN
            SELECT @sSymbol = '%';
        END
        ELSE
        BEGIN
            SELECT @sSymbol = '';
        END
    END
    ELSE
    BEGIN
        SELECT @sSymbol = '%';
    END

    IF @ProjectNo IS NOT NULL AND LEN(@ProjectNo) > 0
    BEGIN
        SELECT @ProjectNo = @sSymbol + @ProjectNo + '%'
        SELECT @sql = @sql + ' and t1.ProjectNo like @ProjectNo '
    END

    IF @CustomerId IS NOT NULL AND LEN(@CustomerId) > 0
    BEGIN
        
        SELECT @sql = @sql + ' and t1.CustomerId = @CustomerId '
    END
    IF @ProjectTypeId IS NOT NULL AND LEN(@ProjectTypeId) > 0
    BEGIN
        
        SELECT @sql = @sql + ' and t1.ProjectTypeId = @ProjectTypeId '
    END


    IF @StartDate IS NOT NULL
    BEGIN
        
        SELECT @sql = @sql + ' and t1.StartDate >= @StartDate '
    END

    IF @StartDate IS NOT NULL
    BEGIN
        
        SELECT @sql = @sql + ' and t1.EndDate <= @EndDate '
    END

    IF @StatusId IS NOT NULL
    BEGIN
        
        SELECT @sql = @sql + ' and t1.StatusId = @StatusId '
    END

    IF @BranchId IS NOT NULL
    BEGIN
        
        SELECT @sql = @sql + ' and t1.BranchId = @BranchId '
    END

    IF @OrderBy IS NOT NULL and len(@OrderBy) > 0
    BEGIN
        SELECT @sql = @sql + ' order by ' + @OrderBy;
    END
   
    -- EXECUTE SQL
    SELECT @paramlist = '@ProjectNo nvarchar(50)'
                    +',@CustomerId bigint'
                    +',@ProjectTypeId bigint'
                    +',@StartDate datetime'
                    +',@EndDate datetime'
                    +',@StatusId bigint'
                    +',@BranchId bigint';
   
    EXEC sp_executesql @sql, @paramlist, @ProjectNo,@CustomerId,@ProjectTypeId,@StartDate,@EndDate,@StatusId,@BranchId
END   


编程少年基地——少年编程者的练兵场
http://bcsn.    招聘版主中

2010-12-24 14:21
growingbird
Rank: 1
等 级:新手上路
帖 子:68
专家分:5
注 册:2008-12-24
收藏
得分:0 
楼上的兄弟谢谢你的回复,我现在想实现的就是实现多条件搜索后,将搜索出来的结果放在临时表里进行分页处理;哎,现在就卡在存储过程这里了
2010-12-24 15:24
mywei1989
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-12-24
收藏
得分:0 
提示: 该帖被管理员或版主屏蔽
2010-12-24 15:27
kevintang
Rank: 4
等 级:业余侠客
威 望:9
帖 子:799
专家分:236
注 册:2008-2-14
收藏
得分:0 
提示: 该帖被管理员或版主屏蔽

编程少年基地——少年编程者的练兵场
http://bcsn.    招聘版主中

2010-12-24 17:34
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
本版块仅限技术交流 请不要发过激言论 [晕 4楼在多发几次这样的言论就好了 我不多大哥好多年!]

[ 本帖最后由 wangnannan 于 2010-12-25 10:07 编辑 ]

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-12-25 08:27
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
嘿嘿~什么情况什么情况什么情况~
2010-12-25 10:55
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
两个家伙骂起来了 晕 怎么火气都这么大

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-12-25 13:24
快速回复:多条件不定查询转换为存贮过程怎么弄啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048568 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved