SELECT REPLACE(lh,'-','0')lh,CAST(ylh AS INT)ylh FROM 表名
你试下~~
你试下~~
解决方案 »
- 求助
- 查询一张表,如果表中值是NULL,则显示“未知” !!
- 入门问题
- 真怪,dtproperties表,在查询分析器中是用户表,可是在企业管理器中则显示为系统表,是不是sql server2000的bug呀?
- 一个事务返回值的问题,困扰好久了!
- 安装SQL2005时候报0x74bb1a02指令引用的0x74bb1a02内存。该内存不能为written
- 定义表变量
- sql server 2005+delphi7 用 联合查询 query1.edit修改查询值 报cannot be modified 错误
- 让我不能理解的结果(T_SQL)
- 下列触发器中的代码在语法检查时始终提示错误‘列前缀hl_kczk与查询中所用的表名或别名不匹配’?
- 两个数据库非完全同步
- 问下,触发器里面究竟怎么判断字段为空?
insert into @tab
select '12','3' union all
select '16-5','02' union all
select '16-12','03' union all
select '1201','7' union all
select '17-8','09' union all
select '11-02','05' union all
select '19','01' union all
select '221-3','11'select case when charindex('-',lh)>0 then substring(lh,1,charindex('-',lh)-1)+right('00'+substring(lh,charindex('-',lh)+1,len(lh)),2)
else lh end as lh,cast(ylh as int) as ylh
from @tab
不明白alimake也是一堆判断~~
with cte as
(select '16-5' as lh,'02' as ylh union all
select '16-12' as lh,'02' as ylh union all
select '17-8' as lh,'09' as ylh union all
select '11-02' as lh,'05' as ylh union all
select '19' as lh,'01' as ylh union all
select '221-3' as lh,'11' as ylh )
select case when CHARINDEX('-',lh)=0 then lh
when LEN(lh)-CHARINDEX('-',lh)=1 then REPLACE(lh,'-','0')
when LEN(lh)-CHARINDEX('-',lh)=2 then REPLACE(lh,'-','')
end as lh,convert(int,ylh) as yhl from cte --结果
lh yhl
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------
1605 2
1612 2
1708 9
1102 5
19 1
22103 11(6 行受影响)这不是回复过了吗, 我刷了半天。就说已经结贴了这么又来了。