首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

写存储过程 查询表,得到俩个整数做比较,如果a>b,status=0,否则status=1解决方案

2012-05-21 
写存储过程 查询表,得到俩个整数做比较,如果ab,status0,否则status1写存储过程 查询表,得到俩个整数做

写存储过程 查询表,得到俩个整数做比较,如果a>b,status=0,否则status=1
写存储过程 查询表,得到俩个整数做比较,如果a>b,status=0,否则status=1
create table test
(
a int ,
b.int ,
statur int default 0
)

insert into test values(1,12,0),(32,2,0),(1,12,0),(1,12,0),(1,12,0),(1,12,0);

[解决办法]

SQL code
update testset statur=(case when a>b then 0 else 1 end)--直接更新就好了吧,不用存储过程哈
[解决办法]
探讨
SQL code

create table test
(
a int ,
b int ,
STATUS AS (CASE WHEN a > b THEN 0 ELSE 1 END) ) --用计算列来的更直接些


INSERT INTO test(a,b)
SELECT 1,2
UNION ALL
SELECT 3,4
UNION ALL
SELECT 6,5
……

热点排行