W~C停用

导航

Sql语句注册公司的事务

use MustGoHome;

--公司注册
if exists(select * from Sysobjects where name='usp_CompanyRegister')
drop procedure usp_CompanyRegister;
go
create procedure usp_CompanyRegister(
--参数



--公司注册地址
@CompanyRegisterCountriesAddressId int,
@CompanyRegisterProvinceAddressId int,
@CompanyRegisterCityAddressId int,
@CompanyRegisterDistrictAddressId int,
@CompanyRegisterDetailedAddress nvarchar(100),


@CompanyRegisterCountriesAddressName nvarchar(40),
@CompanyRegisterProvinceAddressName nvarchar(40),
@CompanyRegisterCityAddressName nvarchar(40),
@CompanyRegisterDistrictAddressName nvarchar(40),

--现居住地址信息
@CompanyNowCountriesAddressId int,
@CompanyNowProvinceAddressId int,
@CompanyNowCityAddressId int,
@CompanyNowDistrictAddressId int,
@CompanyNowDetailedAddress nvarchar(100),

@CompanyNowCountriesAddressName nvarchar(40),
@CompanyNowProvinceAddressName nvarchar(40),
@CompanyNowCityAddressName nvarchar(40),
@CompanyNowDistrictAddressName nvarchar(40),


--公司信息表
@LegalPersonName nvarchar(20),--法人姓名
@LegaKey varchar(20),--法人必回家账号
@HeadName nvarchar(20),--负责人姓名
@HeadKey varchar(20),--负责人必回家账号
@HeadPhone char(11),--负责人电话
@BusinessLicensePath varchar(100),--营业执照照片地址
@LogoPath varchar(100),--Logo图片地址



@CompanyName nvarchar(100),--公司名字
@SociaUniformCode varchar(20)--公司社会统一代码(税号)


)


as
    declare @errorSum int
    set @errorSum=0


    --获得公司注册和当前地址的DataId
declare @CompanyRegisterAddressDataId  Uniqueidentifier 
set @CompanyRegisterAddressDataId=NEWID();--公司注册地址DataId

declare @CompanyNowAddressDataId  Uniqueidentifier 
set @CompanyNowAddressDataId=NEWID();--公司当前地址DataId

declare @CompanyDataId  Uniqueidentifier 
set @CompanyDataId=NEWID();--公司信息DataId



    begin transaction
    begin
    --将公司注册地址信息添加到公司注册地址表
    insert into CompanyRegisteAddress_Table (DataId,CountryId,CountryName,ProvinceId,ProvinceName,CityId,CityName,DistrictId,DistrictName,DetailedAddress) values (@CompanyRegisterAddressDataId,@CompanyRegisterCountriesAddressId,@CompanyRegisterCountriesAddressName,@CompanyRegisterProvinceAddressId,@CompanyRegisterProvinceAddressName,@CompanyRegisterCityAddressId,@CompanyRegisterCityAddressName,@CompanyRegisterDistrictAddressId,@CompanyRegisterDistrictAddressName,@CompanyRegisterDetailedAddress)
    set @errorSum=@errorSum+@@ERROR

    --将公司当前地址信息添加到公司现地址表
    insert into CompanyCompanyNowAddress_Table (DataId,CountryId,CountryName,ProvinceId,ProvinceName,CityId,CityName,DistrictId,DistrictName,DetailedAddress) values (@CompanyNowAddressDataId,@CompanyNowCountriesAddressId,@CompanyNowCountriesAddressName,@CompanyNowProvinceAddressId,@CompanyNowProvinceAddressName,@CompanyNowCityAddressId,@CompanyNowCityAddressName,@CompanyNowDistrictAddressId,@CompanyNowDistrictAddressName,@CompanyNowDetailedAddress)
    set @errorSum=@errorSum+@@ERROR
    
    --将公司信息添加到公司信息表
    insert into CompanyInfomation_Table (DataId,LegalPersonName,LegaKey,CompanyRegisterAddressDataId,CompanyNowAddressDataId,HeadName,HeadKey,HeadPhone,BusinessLicensePath,LogoPath) values (@CompanyDataId,@LegalPersonName,@LegaKey,@CompanyRegisterAddressDataId,@CompanyNowAddressDataId,@HeadName,@HeadKey,@HeadPhone,@BusinessLicensePath,@LogoPath)
    set @errorSum=@errorSum+@@ERROR

    --将数据添加到公司表
    insert into Company_Table (CompanyInfo,SociaUniformCode,CompanyName) values (@CompanyDataId,@SociaUniformCode,@CompanyName)
    set @errorSum=@errorSum+@@ERROR

        if(@errorSum>0)
        rollback transaction
        else
        commit transaction
    end
go

 

posted on 2021-05-03 18:43  W~C停用  阅读(73)  评论(0编辑  收藏  举报