This is accepting values from a form...there is a index on the client firstname, searchname combo...not sure if it is set up correctly....
Create proc VKFORMS_SPAddCLIENT @fName varchar(50),@sName varchar(50),@address varchar(8000),@city varchar(20),@state varchar(20),@country varchar(20),
@zip varchar(20),@phone varchar(25),@fax varchar(25),@email varchar(50),@industrycode int, @PIC int,@RM int,@CGroup int,@Notes varchar(8000),@URL varchar(50),
@createdBy int,@CrdLimit float(8),@xRisk bit, @xDevel bit,@xFin bit,@xChg bit,@xClient bit,@xBill money,@xVK bit,@xCIVIC bit,@xCFS bit,@xEB bit,
@xWM bit,@xCap bit,@xFileS bit,@xCase bit,@xProFX bit,@xScope bit
as
--Gets next available ID
declare @doubles as int;
set @doubles = (select count(*) from tblclient where searchname = @sName and firstname = @fName)
if @doubles = 0
begin
declare @id as int;
begin tran
set @id = (select nextkey from tblPrimaryKeyiD with (updlock) where TableName='tblClient')
INSERT INTO tblClient (clientID,clientRef,firstName,searchName,addressDetail,city,county,country,postcode,telephone,fax,email,industrycode,
PartnerID,managerID,clientgroupid,notes,createDate,suspended,xclient,url,createdby, TotalCreditLimit)
VALUES (@id,@id,@fName,@sName,@address,@city,@state,@country,@zip,@phone,@fax,@email,@industrycode, @PIC,@RM,@CGroup,@Notes,
convert(datetime,convert(char(10),getdate(),101)),0,0,@URL,@createdBy,@CrdLimit)
INSERT INTO tblClientExtraDetails (clientID,CARisk,CADevelopment,CAFinancial,CAChanges,SECClient,EstimatedAnnualBillings,FinChgVK,FinChgCivic,
FinChgCFS,FinChgEB,FinChgWM,FinChgVKCAP,CHGFileStorage,CHGCaseware,CHGProfx,CHGScope)
VALUES (@id,@xRisk, @xDevel,@xFin,@xChg,@xClient,@xBill,@xVK,@xCIVIC,@xCFS,@xEB,@xWM,@xCap,@xFileS,@xCase,@xProFX,@xScope)
commit tran
if @@ERROR <> 0
begin
Rollback TRAN
SELECT -1 as CODE
end
else
begin
SELECT @ID as CODE
update tblPrimaryKeyID set nextkey = nextkey + 1 where TableName='tblClient'
end
end
else
begin
SELECT -1 as CODE
end
--if trans goes through return clientid otherwise return -1......
THANKS,
DLC
Create proc VKFORMS_SPAddCLIENT @fName varchar(50),@sName varchar(50),@address varchar(8000),@city varchar(20),@state varchar(20),@country varchar(20),
@zip varchar(20),@phone varchar(25),@fax varchar(25),@email varchar(50),@industrycode int, @PIC int,@RM int,@CGroup int,@Notes varchar(8000),@URL varchar(50),
@createdBy int,@CrdLimit float(8),@xRisk bit, @xDevel bit,@xFin bit,@xChg bit,@xClient bit,@xBill money,@xVK bit,@xCIVIC bit,@xCFS bit,@xEB bit,
@xWM bit,@xCap bit,@xFileS bit,@xCase bit,@xProFX bit,@xScope bit
as
--Gets next available ID
declare @doubles as int;
set @doubles = (select count(*) from tblclient where searchname = @sName and firstname = @fName)
if @doubles = 0
begin
declare @id as int;
begin tran
set @id = (select nextkey from tblPrimaryKeyiD with (updlock) where TableName='tblClient')
INSERT INTO tblClient (clientID,clientRef,firstName,searchName,addressDetail,city,county,country,postcode,telephone,fax,email,industrycode,
PartnerID,managerID,clientgroupid,notes,createDate,suspended,xclient,url,createdby, TotalCreditLimit)
VALUES (@id,@id,@fName,@sName,@address,@city,@state,@country,@zip,@phone,@fax,@email,@industrycode, @PIC,@RM,@CGroup,@Notes,
convert(datetime,convert(char(10),getdate(),101)),0,0,@URL,@createdBy,@CrdLimit)
INSERT INTO tblClientExtraDetails (clientID,CARisk,CADevelopment,CAFinancial,CAChanges,SECClient,EstimatedAnnualBillings,FinChgVK,FinChgCivic,
FinChgCFS,FinChgEB,FinChgWM,FinChgVKCAP,CHGFileStorage,CHGCaseware,CHGProfx,CHGScope)
VALUES (@id,@xRisk, @xDevel,@xFin,@xChg,@xClient,@xBill,@xVK,@xCIVIC,@xCFS,@xEB,@xWM,@xCap,@xFileS,@xCase,@xProFX,@xScope)
commit tran
if @@ERROR <> 0
begin
Rollback TRAN
SELECT -1 as CODE
end
else
begin
SELECT @ID as CODE
update tblPrimaryKeyID set nextkey = nextkey + 1 where TableName='tblClient'
end
end
else
begin
SELECT -1 as CODE
end
--if trans goes through return clientid otherwise return -1......
THANKS,
DLC