日期:2014-05-17 浏览次数:20652 次
create proc proc_Add
@col1 varchar(20),
@col2 varchar(20),
@val1 int,
@val2 int
as
set nocount on
declare @sql varchar(2000)
set @sql='insert into tb('+@col1+','+@col2+') values('+CAST(@val1 as varchar)+','+CAST(@val2 as varchar)+')'
exec (@sql)
go
--drop table tb
create table tb(id int,v varchar(10))
insert into tb(id,v)
values(1,'aa'),
(2,'bb'),
(3,'cc')
select * from tb
/*
id v
1 aa
2 bb
3 cc
*/
create PROCEDURE [dbo].[pro_C]
@userName VARCHAR(250),
@passwordNew VARCHAR(256)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
----your sql
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
--PRINT 'fail'
ROLLBACK TRANSACTION;
END CATCH
END
--建表
--drop table tb
create table tb(id int,v varchar(10))
go
--建存储过程
drop proc dbo.proc_test
go
create proc dbo.proc_test
@sql nvarchar(4000)
as
exec(@sql)
go
--在你的客户端,拼接语句
declare @sql nvarchar(4000)
set @sql = 'set xact_abort on;
begin tran
&nb