当前位置:Gxlcms > 
数据库问题 > 
sql存储过程,根据多个条件查询,返回一个dataTable或者DataSet
                     
                    
                        sql存储过程,根据多个条件查询,返回一个dataTable或者DataSet
                        
                            时间:2021-07-01 10:21:17
                            帮助过:3人阅读
							                        
                     
                    
                    
                     Proc [dbo].
[Proc_Boss_Show]
@StrIndex varchar(
500),
--开始条数
@EndIndex varchar(
500),
--结束条数
@StrWhere  varchar(
max),
@zx int --执行区间  1执行 top n  2显示所有数据
as
begin
     declare  @strSqlstr varchar(
500)
     
     if(
@zx=1)
     begin
         set @strSqlstr=‘select  * from (select top ‘+@EndIndex
         set @strSqlstr+=‘  row_number() over(order by 提货时间 desc)
         as xx,* from View_Boss_Show  where 1=1 ‘+@StrWhere
         set @strSqlstr+=‘ ) as xx where xx>‘+@StrIndex
    end
     if(
@zx=2)
    begin
       set @strSqlstr=‘select * from  View_Boss_Show  where  1=1 ‘+@StrWhere
    end
print @strSqlstr
exec(
@strSqlstr)
asp.net代码(直接用DataTable接收):
DataTable dt = null;
            try
            {
                dt = DBHelper.GetDataTable("Proc_View_show1391", para);
            }
            catch (Exception ex)
            { //throw new Exception(ex.ToString());
            }
 
sql存储过程,根据多个条件查询,返回一个dataTable或者DataSet
标签:一个   max   begin   sel   str   des   proc   new   pre