CREATE PROCEDURE [dbo].[InsertMessage](
@strTable varchar(), --表名
@strValues nvarchar(), --要插入的数据(用英文逗号分隔),如果是字符串类型,需加单引号
@only_field varchar()=NULL, --唯一性字段(列名)
@only_value varchar()=NULL, --唯一性字段值
@msg nvarchar()=NULL --错误消息
)
as
BEGIN SET NOCOUNT ON;
declare @sqlString varchar(); IF @only_field is not null
begin
declare @p int; --查询唯一性结果
declare @sql nvarchar(); --拼接查询sql字串
set @sql='SELECT @p=count(1) FROM ' +@strTable+' WHERE ' +@only_field+'='+@only_value;
exec sp_executesql @sql,N'@p AS int OUTPUT',@p OUTPUT if @p >
begin
raiserror(@msg ,,)
return
end
else
begin
set @sqlString = 'insert into '+@strTable+' values ('+@strValues+')';
exec(@sqlString);
end
end
ELSE
begin
set @sqlString = 'insert into '+@strTable+' values ('+@strValues+')';
exec(@sqlString);
end
END --execute [dbo].[InsertMessage] 'base._Member',"0,2,getdate(),0,1,'4445','654321','654321',N'邹柯00'",'AcctNbr','',N'会员卡号已存在,不能重复添加!'
--execute [dbo].[InsertMessage] 'base._Member',"0,2,getdate(),0,1,'4445','654321','654321',N'邹柯00'",NULL,NULL,NULL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO -- 邹柯
Create PROCEDURE CollegeAdd
(
@username NVarChar()
,@cardid VarChar()
,@age int
,@sex Char()
,@image_path VarChar()
,@job_base_id int
,@level_base_id int
,@certificateid VarChar()
,@certificate_path VarChar()
,@BeginTime DateTime=null
,@EndTime DateTime=null
,@userid int out
,@ceid int out
)
WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRY
BEGIN TRAN; -- Add Tutor
insert into Tutor
( Name, IdentityCard, Age, Gender, Photo)
values (@username, @cardid, @age, @sex, @image_path); -- 获取自增ID
select @userid = scope_identity(); -- Add Certificate
insert into Certificate
( TutorId, JobId, LevelId, BeginTime,EndTime,Id, ImageUrl)
values (@userid, @job_base_id, @level_base_id,@BeginTime, @EndTime,@certificateid, @certificate_path); -- 获取自增ID
select @ceid = scope_identity(); COMMIT TRAN;
END TRY
BEGIN CATCH
ROLLBACK TRAN; throw;
END CATCH
END /*
USE [GmkCollege]
GO DECLARE @return_value int,
@userid int,
@ceid int EXEC @return_value = [dbo].[CollegeAdd]
@username = '测试8',
@cardid = '测试8',
@age = 99,
@sex = '女',
@image_path = '测试8',
@job_base_id = 2,
@level_base_id = 2,
@certificateid = '测试8',
@certificate_path = '测试8',
@BeginTime='2016-06-06',
@EndTime='2017-01-01',
@userid = @userid OUTPUT,
@ceid = @ceid OUTPUT SELECT @userid as N'@userid',
@ceid as N'@ceid' SELECT 'Return Value' = @return_value GO
*/
-- 邹柯
Create PROCEDURE AddSignUpInfo
(
--UserInfo
@Name NVarChar()=null
,@IdCard VarChar()=null
,@Gender Char()=null
,@Area NVarChar()=null
,@Nation NVarChar()=null
,@Hobby NVarChar()=null
,@BirthDate DateTime=null
,@Phone VarChar()=null
,@TrainStatus Char()=null
--UserTransInfo
,@TransOrganizate NVarChar()=null
,@Certicate NVarChar()=null
,@StartTime DateTime=null
,@EndTime DateTime=null
,@Expectation NVarChar()=null
,@TransContent NVarChar()=null
--UserPayInfo
,@OrderNo Varchar()=null
,@Type Int=
,@Amount Int=null
,@Currency Int=
,@Method Int=
,@Status Int=
)
WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRY
BEGIN TRAN;
--声明用户ID变量
declare @UID int=null;
declare @INFO1 int=null;
declare @INFO2 int=null;
declare @INFO3 int=null; --根据身份证号获取用户ID
SELECT @UID=ID FROM UserCaptcha WHERE IdCard=@IdCard; --根据用户ID查询该用户之前是否已添加过报名信息--只是未支付成功或其他原因导致这条信息无效
SELECT @INFO1=Count() FROM UserInfo WHERE UID=@UID;
SELECT @INFO2=Count() FROM UserTransInfo WHERE UID=@UID;
SELECT @INFO3=Count() FROM UserPayInfo WHERE UID=@UID; if @INFO1 =
begin
-- Add UserInfo
insert into UserInfo(
[UId]
,[Name]
,[Gender]
,[Nation]
,[Area]
,[Hobby]
,[BirthDate]
,[Phone]
,[TrainStatus]
)
values(
@UID
,@Name
,@Gender
,@Nation
,@Area
,@Hobby
,@BirthDate
,@Phone
,@TrainStatus
)
end
else
begin
-- Update UserInfo
Update UserInfo SET
[Name]=@Name
,[Gender]=@Gender
,[Nation]=@Nation
,[Area]=@Area
,[Hobby]=@Hobby
,[BirthDate]=@BirthDate
,[Phone]=@Phone
,[TrainStatus]=@TrainStatus
Where UId=@UID
end if @INFO2 =
begin
-- Add UserTransInfo
insert into UserTransInfo(
[UId]
,[TransOrganizate]
,[Certicate]
,[TransContent]
,[Expectation]
,[StartTime]
,[EndTime]
)
values(
@UID
,@TransOrganizate
,@Certicate
,@TransContent
,@Expectation
,@StartTime
,@EndTime
);
end
else
begin
-- Update UserTransInfo
Update UserTransInfo SET
[TransOrganizate]=@TransOrganizate
,[Certicate]=@Certicate
,[TransContent]=@TransContent
,[Expectation]=@Expectation
,[StartTime]=@StartTime
,[EndTime]=@EndTime
Where UId=@UID
end if @INFO3 =
begin
-- Add UserPayInfo
insert into UserPayInfo(
[UId]
,[OrderNo]
,[Type]
,[Amount]
,[Currency]
,[Method]
,[Status]
)
values(
@UID
,@OrderNo
,@Type
,@Amount
,@Currency
,@Method
,@Status
);
end
else
begin
-- Update UserPayInfo
Update UserPayInfo SET
[OrderNo]=@OrderNo
,[Type]=@Type
,[Amount]=@Amount
,[Currency]=@Currency
,[Method]=@Method
,[Status]=@Status
Where UId=@UID
end
COMMIT TRAN;
END TRY
BEGIN CATCH
ROLLBACK TRAN; throw;
END CATCH
END /*
USE [GmkCollege]
GO DECLARE @return_value int EXEC @return_value = [dbo].[AddSignUpInfo]
@Name = 'zouke',
@IdCard = '111111',
@Gender = 1,
@Area = 'zzzzzzzz',
@Nation = '汉族',
@Hobby = '足球、篮球呢',
@BirthDate = '2016-01-01',
@Phone = '18761939022',
@TrainStatus = 1,
@TransOrganizate = 'GMK',
@Certicate = '理疗师',
@StartTime = '2011-01-01',
@EndTime = '2012-01-01',
@Expectation = 'cccccccc',
@TransContent = 'ddddddd',
@OrderNo="2222222222",
@Type=1,
@Amount=100,
@Currency=2,
@Method=1,
@Status=1, SELECT 'Return Value' = @return_value GO
*/

sqlserver 存储过程 增加的更多相关文章

  1. SqlServer存储过程学习笔记(增删改查)

    * IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值. CREATE PROCEDURE [dbo].[PR_NewsAffiche_AddNewsEntity] ( ...

  2. SQLSERVER存储过程语法详解

    CREATE PROC [ EDURE ] procedure_name [ ; number ] [ { @parameter data_type } [ VARYING ] [ = default ...

  3. SqlServer存储过程(增删改查)

    * IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值. CREATE PROCEDURE [dbo].[PR_NewsAffiche_AddNewsEntity] ( ...

  4. SQLSERVER存储过程的基本语法实例

    SQLSERVER存储过程的基本语法实例 SQLSERVER存储过程的基本语法实例 一.定义变量--简单赋值 declare @a intset @a=5 print @a --使用select语句赋 ...

  5. 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)

    解剖SQLSERVER 第十五篇  SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...

  6. Sqlserver 存储过程中结合事务的代码

    Sqlserver 存储过程中结合事务的代码  --方式一 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ ...

  7. SQLServer 存储过程嵌套事务处理

    原文:SQLServer 存储过程嵌套事务处理 某个存储过程可能被单独调用,也可能由其他存储过程嵌套调用,则可能会发生嵌套事务的情形. 下面是一种解决存储过程嵌套调用的通用代码,在不能确定存储过程是否 ...

  8. 创建并在项目中调用SQLSERVER存储过程的简单示例

    使用SQLSERVER存储过程可以很大的提高程序运行速度,简化编程维护难度,现已得到广泛应用.创建存储过程 和数据表一样,在使用之前需要创建存储过程,它的简明语法是: 引用: Create PROC ...

  9. SqlServer存储过程详解

    SqlServer存储过程详解 1.创建存储过程的基本语法模板: if (exists (select * from sys.objects where name = 'pro_name')) dro ...

随机推荐

  1. python 多线程批量传文件

    #!/usr/bin/env python #_*_ coding:utf-8 -*-#autho:leiyong#time:2017-06-05#version: 1.3 import parami ...

  2. openSUSE 13.1 搭建 DNS服务器

    1. Setup Primary DNS Server Install bind9 BIND (Berkely Internet Name Domain) is a software for tran ...

  3. tungsten-replicator安装

    需要环境 ruby1.8.5 or laterJava1.6 or later 应用程序对外开放接口 3306 (MySQL database)2112 (Tungsten THL)10000 (Tu ...

  4. python - dict.setdefault

    index = dict.serdefault(key,default) 尝试往dict中插入新键值key,如果key已存在就原dict不变,否则插入key:defalut:返回值为key在dict中 ...

  5. 《java.util.concurrent 包源码阅读》03 锁

    Condition接口 应用场景:一个线程因为某个condition不满足被挂起,直到该Condition被满足了. 类似与Object的wait/notify,因此Condition对象应该是被多线 ...

  6. Python之登录接口

    要求 1.输入用户名密码2.认证成功后显示欢迎信息3.输错三次后锁定 思路 没有数据库,这里使用本地文件,一共需要两个文件:       黑名单的文件:黑名单里检测,不让登录     用户信息文件:将 ...

  7. Android Lint的使用

    一.概述 Android Lint是在ADT 16(和 Tools 16)引入的一个新工具,可以扫描Android 项目源码中潜在的bug .例如: 缺少翻译(和未使用的翻译)布局性能问题(老的lay ...

  8. 虚拟机下 solr7.1 cloud 集群搭建 (手动解压和官方脚本两种方式)

    准备工作: vmware workstation 12,OS使用的是ubuntu16.04,三台虚拟机搭建一个solr集群,zookeeper共用这三台虚拟机组成zookeeper集群. zookee ...

  9. Resin4安装配置

    #Resin4安装配置 # Resin4安装配置 #centos6 #参考http://467754239.blog.51cto.com/4878013/1558435 #yum -y install ...

  10. ssh免密验证,shell批量设置

    ssh免密验证,shell批量设置 #ssh免密验证,shell自动设置 echo '#!/bin/sh . /etc/init.d/functions [[ -f /usr/bin/expect ] ...