USE [ACCOUNT_DBF]
GO

/****** Object:  StoredProcedure [dbo].[usp_createAccount]    Script Date: 05/07/2013 10:50:01 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_createAccount]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_createAccount]
GO

USE [ACCOUNT_DBF]
GO

/****** Object:  StoredProcedure [dbo].[usp_createAccount]    Script Date: 05/07/2013 10:50:01 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[usp_createAccount]
@account varchar(32),
@pw varchar(32),
@cash int = 0,
@email varchar(100) = '',
@gefra smallint = 0,
@geant varchar(50),
@birthday varchar(10),
@ip varchar(39),
@lang varchar(3)
as
set nocount on
set xact_abort on

if not exists (select * from ACCOUNT_TBL where account = @account)
begin


	begin tran
	INSERT ACCOUNT_TBL(account,password,isuse,member,id_no1,id_no2,realname,OldPassword,cash)
	VALUES(@account, @pw, 'T', 'A', @pw, @pw, 'P',@pw, @cash)
	INSERT ACCOUNT_TBL_DETAIL(account,gamecode,tester,m_chLoginAuthority,regdate,BlockTime,EndTime,WebTime,isuse,secession, email,secretquestion,secretanswer,birthday,regIP)
	VALUES(@account,'A000','2','F',GETDATE(),CONVERT(CHAR(8),GETDATE()-1,112),CONVERT(CHAR(8),DATEADD(year,10,GETDATE()),112),CONVERT(CHAR(8),GETDATE()-1,112),'T',NULL, @email, @gefra, @geant, @birthday,@ip)

	if @@error <> 0
	begin
		rollback tran
		select -1
	end
	else
	begin
		commit tran
		select 1
	end
end
else
begin
	select 0
end

GO

