1.判斷是否存在這樣的記錄 if not exists 和 if exists 相對應
例:使用者是否存在 if not exists
if exists (select 1 from user(nolock) where username='abcd')
begin
print '使用者存在'
end
else
begin
print '使用者不存在'
end
2. 判斷取出的值是否為空isnull
if isnull(@ls_parmvalue,'n')='n'
這種判斷當 @ls_parmvalue='' 這種情況下列印的值是乙個空白符,不是n,所以當要判斷這個存在值,並且不為空白符的情況
if isnull(@ls_parmvalue,'')<>''
這個判斷能滿足這個值不為空的情況。
3.判斷取出的值是否為空dbo.empty
dbo.empty(@ls_parmvalue)=0 表示 ls_parmvalue的值為空,包括'' ,null,null
if dbo.empty(@ls_parmvalue)=0
begin
print '@ls_parmvalu值為空'
end
else
begin
print '@ls_parmvalu值不為空'
end
SqlServer儲存過程中迴圈的使用
1.while迴圈 格式示例如下 declare iint set i 1 while i 30begin insert into test userid values i set i i 1end2.游標迴圈 格式示例如下 declare a1varchar 10 a2varchar 10 a3i...
sqlserver中在儲存過程中寫事務
由於對資料的操作經常需要併發,所以在儲存過程中使用事務是非常必要的,我經常這樣處理 if exists select from sys.objects where name sp drop proc sp gocreate procedure sp 引數列表.out bit 0 output 輸出引...
儲存過程中呼叫儲存過程
use northwind go 儲存過程1 功能 通過員工firstname inputempfirstname 獲得 員工id outid if exists select name from sysobjects where name p getempleeidbyname and type ...