MSSQL儲存過程應用

2022-08-12 02:12:19 字數 1669 閱讀 7943

1.原始表inoutinfo

2.現在想輸入時間範圍和操作型別輸出對應的結果

2.1建立儲存過程

create proc selecttype

@type nvarchar(10),@starttime datetime,@endtime datetime

asselect opdt,opemp,optype,num from inoutinfo where optype=@type and opdt between @starttime and @endtime

go2.2執行儲存過程

exec selecttype '入庫','2019-01-18 23:15:25.100','2019-01-18 23:15:25.113'

3.現在想輸入時間範圍查詢所有種類的各自操作的數量

3.1修改儲存過程

alter proc selecttype

@starttime datetime,@endtime datetime

asselect optype,sum(num) from inoutinfo where opdt between @starttime and @endtime group by optype

go3.2執行儲存過程

4.現在想輸入查詢型別,時間範圍輸出明細或彙總

4.1修改儲存過程

alter proc selecttype

@selecttype nvarchar(10),@type nvarchar(10),@starttime datetime,@endtime datetime

asif(@selecttype='彙總')

select optype,sum(num) from inoutinfo where opdt between @starttime and @endtime group by optype

else

select opdt,opemp,optype,num from inoutinfo where optype=@type and opdt between @starttime and @endtime

go4.2執行儲存過程

exec selecttype '','消耗','2019-01-18 01:15:25.100','2019-01-19 13:20:25.113'

exec selecttype '彙總','','2019-01-18 01:15:25.100','2019-01-19 13:20:25.113'

MSSQL儲存過程

sqlserver 帶有返回值,儲存過程同時新增兩張表,並將第一張表的主鍵插入第二張表當中 2010 07 04 22 00 55 分類 sql 字型大小 訂閱 sql server 中,可以使用 scope identity identity ident current 來取得最後插入記錄的值值,...

mssql 通用儲存過程

create proc commonpagination columns varchar 500 要顯示的列名,用逗號隔開 tablename varchar 100 要查詢的表名 ordercolumnname varchar 100 排序的列名 order varchar 50 排序的方式,公升...

MSSQL翻頁儲存過程

create procedure dbo showpage tblname varchar 255 表名 strgetfields varchar 1000 需要返回的列 strorder varchar 255 排序的欄位名 startrowindex int 0,取的第一行在結果有的序號 從第幾...