본문 바로가기

DB/M$SQL

저장 프로시저 (Store Procedure) 예제

[스토어드프로스져 예제]

CREATE proc spAccount_list
 @name   varchar(20)
 , @accountidx   int
 , @nickname   varchar(12)
 , @result   int OUT /* 0 -ok, 1 - error, 2 - exist */
as
begin
 declare @name_db varchar(255)
 declare @name_db_where varchar(255)
 set @result = 0
 set nocount on
 set @name_db=ASCII(left (@name,1))
 set @name_db_where = @name_db%5
 select accountidx from account_list where accountidx = @accountidx
 if @@rowcount <> 0
   begin
  set @result = 2
  return
 end
 insert into account_list (
  accountidx,
  accountid,
  accountnick,
  where_db
  ) values (
  @accountidx
  ,@name
  ,@nickname
  ,@name_db_where
  )
 
 if @@error <> 0
  goto proc_error
proc_error:
 set @result = 1
 return
end /* spAccount_list */
GO

exec spAccount_list '바보', '001','나바보아냐',''

'DB > M$SQL' 카테고리의 다른 글

Alter Table  (0) 2008.05.21
MSSQL DB 복구 후 사용자 계정 매칭  (0) 2008.04.11
간단한 where 날자 검색  (0) 2007.08.12
MSSQL connect for Windows 2003  (0) 2007.05.19
MSSQL connect for Windows 2003  (0) 2007.05.18