建立乙個儲存過程,查詢在校生

2022-03-31 10:34:53 字數 1323 閱讀 9545

一直都是臨時寫語句,現在一次性建立儲存過程,日後直接呼叫就好。

create

procedure

sp_zaixiao

asdeclare

@curyear

intdeclare

@curmonth

intdeclare

@tolrow

intdeclare

@strsql

varchar

(200

)set@curyear

=year

(getdate

())set@curmonth

=month

(getdate

())if@curmonth

>

7select

case

when

dwdm='

4420000

'then

'校本部

'else'分校

'endas'單位

',count

(xh) as'

人數'from

xsjbdab 

where

xjztdm='

1'andnj

>

(@curyear-3

)  and

xslbdm

<>'61

'groupby(

case

when

dwdm='

4420000

'then

'校本部

'else'分校

'end)

else

select

case

when

dwdm='

4420000

'then

'校本部

'else'分校

'endas'

單位',

count

(xh) as'

人數'from

xsjbdab 

where

xjztdm='

1'andxslbdm

<>'61

'and( nj

>

(@curyear-3

) or

(nj=

(@curyear-3

) and

zsjj='

3'))

groupby(

case

when

dwdm='

4420000

'then

'校本部

'else'分校

'end)

MySql建立乙個儲存過程

mysql 儲存過程是從 mysql 5.0 新功能。儲存過程的長處有一籮筐。只是最基本的還是執行效率和sql 封裝。特別是 sql 封裝功能,假設沒有儲存過程,在外部程式訪問資料庫時 比如 php 要組織非常多 sql 語句。特別是業務邏輯複雜的時候,一大堆的 sql 和條件夾雜在 php 中,讓...

乙個傳入查詢的儲存過程

exec r test select from gdgoods create procedure r test testserch varchar 100 asdeclare serch varchar 100 set serch testserch exec serch godeclare ser...

乙個分頁查詢的儲存過程

乙個分頁查詢的儲存過程 函式 目的 寫乙個分頁查詢的儲存過程,方便分頁查詢,直接呼叫即可 說明 使用northwind資料庫中的employees表 建立儲存過程的函式 create function dbo maxdate page int,count int returns int asbegi...