sql存儲過程,根據多個條件查詢,返回一個dataTable或者DataSet


不廢話,先直接代碼

首先sql部分(我在這里加了一個@zx作為判斷,一般不需要這個參數):

ALTER 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());
            }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM