首页 新闻 会员 周边 捐助

SQL中存储过程的问题

0
悬赏园豆:20 [已解决问题] 解决于 2014-12-29 13:47

Alter table [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0] add [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] nvarchar(200)


update [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0] set [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] = (select [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] from [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] where [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[SYSTEM_ID] = [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[SYSTEM_ID])WHERE EXISTS (SELECT 1 FROM [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] WHERE [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[SYSTEM_ID] = [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[SYSTEM_ID])


update [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] set [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06]=null


ALTER TABLE [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] DROP COLUMN [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06]

这四个sql语句怎样写在一个存储过程中

菜鸟起飞啊的主页 菜鸟起飞啊 | 初学一级 | 园豆:15
提问于:2014-12-29 11:04
< >
分享
最佳答案
0


BEGIN TRY
BEGIN TRAN
/*SQL 脚本的删增改*/


COMMIT TRAN

END TRY
BEGIN CATCH

ROLLBACK TRAN
END CATCH

收获园豆:15
KingMi | 小虾三级 |园豆:1344 | 2014-12-29 11:35

为什么提示说begin try有语法错误了

begin try

Alter table [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0] add [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] nvarchar(200)
update [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0] set [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] = (select [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06] from [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] where [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[SYSTEM_ID] = [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[SYSTEM_ID])WHERE EXISTS (SELECT 1 FROM [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2]WHERE [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2].[SYSTEM_ID] = [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_0].[SYSTEM_ID])
update [Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] set [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06]=null
ALTER TABLE [dbo].[Form_016336CC-C7FA-43D2-9EA5-C3F9A5B47A50_2] DROP COLUMN [ITEM_015afb1d-28de-4389-a6a1-e2dbdd89fa06]
COMMIT 
end try
begin catch
rollback 
end catch

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 12:35

@小菜鸟5: ods,你怎么把 BEGIN TRAN 给省略了,还有COMMIT TRAN ,ROLLBACK TRAN 写全好么,另你的MSSS 版本多少?

KingMi | 园豆:1344 (小虾三级) | 2014-12-29 13:06

@英雄莫问出处: sql server2012

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:10

@英雄莫问出处: 我写全了也是一样的错误

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:30

@小菜鸟5: 怎么会了,我的2008 R2的OK 啊,你把你写的SQL语句单独一起执行可以吗

KingMi | 园豆:1344 (小虾三级) | 2014-12-29 13:49

@英雄莫问出处: 单独可以

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:50

@英雄莫问出处: 报错是BEGIN附近有语法错误

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:51

@英雄莫问出处: 我知道了我掉了一个as

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:55

@小菜鸟5: 你把报错的整个语句发我看看,是不是漏了什么BEGIN/END  

KingMi | 园豆:1344 (小虾三级) | 2014-12-29 13:57

@英雄莫问出处: 我掉了一个AS,要在begin上加一个AS就不会报错了

菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 13:59
其他回答(1)
0

直接创建一个新的存储过程,把你的sql语句放进去就OK了,不管几条,都可以

收获园豆:5
瀟X謝 | 园豆:221 (菜鸟二级) | 2014-12-29 11:07

出现回滚怎样解决啊

支持(0) 反对(0) 菜鸟起飞啊 | 园豆:15 (初学一级) | 2014-12-29 11:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册