写存储过程 查询表,得到俩个整数做比较,如果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);
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 Server?
- 求助:两张表的联合查询
- mssql代理维护计划执行t——sql语句
- sql下有xp_cmdshell,Oracle下有相对应的是啥啊?
- 怎么样知道表company中id从1到5000之间有多少个id是没有的呢?
- Sqlserver,select top 100 from a 然后将这100条的Status标记为1,证明已读
- 求一SQL语句,字段重复的数据只需要显示一条
- 数据库的的表怎么打不开?
- 用VC访问Oracle的BLOB字段问题
- 已知数据库服务器的机器名称,如何查询该服务器上有哪些数据库?
- 十分怪异的2008R2界面问题
- 人在国外,急求帮助,谢谢。
update test
set statur=(case when a>b then 0 else 1 end)--直接更新就好了吧,不用存储过程哈
(
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,5SELECT * FROM Test
/*
a b STATUS
1 2 1
3 4 1
6 5 0*/
set statur=(case when a>b then 0 else 1 end)
a=(case when a>b then b else a end)
有没有办法不用在重复一次case when a>b
update test
set statur=(case when a>b then 0 else 1 end,
a=(case when a>b then b else a end)这样不可以吗?
(
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);update test
set statur=(case when a>b then 0 else 1 end),
a=(case when a>b then b else a end)select * from test/*
a b statur
1 12 1
2 2 0
1 12 1
1 12 1
1 12 1
1 12 1
*/