儲存過程分頁,帶參,返回值

2021-08-07 11:52:20 字數 3393 閱讀 4272

create procedure [dbo].[nb_arrearagelistbycar] 

@pageindex int, --第幾頁

@pagesize int, --分頁大小

@carnumber nvarchar(6), --車牌號

@rstatus int output, --返回標識號 0 成功

@rcode int output, --返回錯誤編碼

@rmsg varchar(128) output --返回描述狀態說明標識

asdeclare @ret int --臨時引數

declare @sql varchar(max)

begin

begin try

-->step 1 | 空值檢測 |

if(@pageindex is null or 0 = @pageindex or @pagesize is null or 0 = @pagesize )

begin

set @rstatus = 1

set @rcode = 4000

set @rmsg = '引數空'

select -1 rn,'' code,'' startdate ,-1 remoney, -1 lastmoney

return

end--條件篩選

declare @sql_where nvarchar(max)

declare @start1 nvarchar(16)

declare @end1 nvarchar(16)

set @sql_where = ''

set @start1 = ''

set @end1 = ''

set @start1 = cast((@pagesize * (@pageindex-1) + 1) as varchar(16))

set @end1 = cast(@pagesize* @pageindex as varchar(16))

if('' != @carnumber and @carnumber is not null)

begin

set @sql_where = @sql_where + n' and b.code = '''+ @carnumber +''' '

end-->step 2 | 分頁資料 |

declare @count1 int

set @count1 = 0

declare @t_sql nvarchar(max)

set @t_sql = n'select @c = count(1)

from (

select a.parkorderid,sum(isnull(c.ordermoney,0)) remoney

from parkorder a left join parkspace b on b.spaceid = a.spaceid

left join orderpaybank c on c.orderid = a.parkorderid

where a.totalmoney - a.remoney > 0 and a.spacestatus = 2 ' + @sql_where + '

group by a.parkorderid) a

left join parkorder b on b.parkorderid = a.parkorderid

left join parkspace c on c.spaceid = b.spaceid

where 1 = 1'

exec sp_executesql @t_sql,n'@c int output', @count1 output

set @t_sql = ''

if(0 = @count1)

begin

set @rstatus = 1

set @rcode = 0

set @rmsg = '沒有欠款記錄'

select -1 rn,'' code,'' startdate ,-1 remoney, -1 lastmoney

return

endelse

begin

set @rcode = @count1

set @t_sql = n'select * from (

select row_number() over (order by c.code) rn,

b.parkorderid,c.code,convert(char(20),b.startdate,120) startdate,convert(char(20),b.enddate,120) enddate,ltrim(rtrim(b.carnumber)) carnumber,

datediff(minute,b.startdate,b.enddate) howlong,a.remoney,

b.totalmoney - a.remoney lastmoney

from (

select a.parkorderid,sum(isnull(c.ordermoney,0)) remoney

from parkorder a left join parkspace b on b.spaceid = a.spaceid

left join orderpaybank c on c.orderid = a.parkorderid

where a.totalmoney - a.remoney > 0 and a.spacestatus = 2 ' + @sql_where + '

group by a.parkorderid) a

left join parkorder b on b.parkorderid = a.parkorderid

left join parkspace c on c.spaceid = b.spaceid

where 1 = 1

) ch where ch.rn between ' + @start1 + ' and ' + @end1

exec sp_executesql @t_sql

set @rstatus = 0

set @rmsg = '獲取成功'

endend try

begin catch

set @rstatus = -1

set @rcode = -1

set @rmsg = error_message()

insert into parkerr(proname,protime,proerr)values('[nb_arrearagelist]',getdate(),error_message())

end catch

end

oracle帶返回值的儲存過程

create table tb storage id number 9 shopid varchar 10 storage number 10 not null table created create table tb shop id number 9 shopid varchar 10 shop...

oracle帶返回值的儲存過程

create table tb storage id number 9 shopid varchar 10 storage number 10 not null table created create table tb shop id number 9 shopid varchar 10 shop...

儲存過程返回值

alter procedure dbo.spdelstudentbyid id int,result int output parameter1 int 5,parameter2 datatype output asset nocount on 不返回計數當 set nocount 為 on 時,不...