日期:2014-05-17  浏览次数:20411 次

存储过程实现下述功能
初次接触存储过程,遇到一个问题,希望各位帮帮忙!谢谢!

把上面这个表中的Position字段中的1修改成2,2修改成1,用存储过程怎么去实现?
存储 Sql

------解决方案--------------------
----------------------------
-- Author  :DBA_Huangzj(發糞塗牆)
-- Date    :2013-09-30 17:48:48
-- Version:
--      Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64) 
-- Jun 10 2013 20:09:10 
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go 
create table [huang]([roleid] int,[position] int,[itemid] int)
insert [huang]
select 1,1,1 union all
select 1,1,2 union all
select 1,1,3 union all
select 2,2,4 union all
select 2,2,5 union all
select 2,2,6
--------------开始查询--------------------------

select * from [huang]
update [huang]
set position=case when position=1 then 2 when position=2 then 1 end 
SELECT * FROM [huang]
----------------结果----------------------------
/* 
roleid      position    itemid
----------- ----------- -----------
1           1           1
1           1           2
1           1           3
2           2           4
2           2           5
2           2           6


roleid      position    itemid
----------- ----------- -----------
1           2           1
1           2           2
1           2           3
2           1           4
2 &n