--楼主没说结果怎么来的。只能猜测了。取后边3位中不是数值的。
select bh,mc
from tablename
where isnumeric(right(bh,3))=0
select bh,mc
from tablename
where isnumeric(right(bh,3))=0
解决方案 »
- 请问 如何 将 decimal 负数 转化为 正数
- 请问,IN 运算符可以这么用吗?
- SQL 权限问题:没有给登录名任何服务器角色. 但是登录后还能操作登录名映射外的其它数据库
- 请教一个触发器的问题.
- 请教"BULK INSERT TEMP FROM 'D:\WORK\Andon\temp.xls'"
- 数据存储过程中的一个问题
- 小数点后位数的问题
- 请教,sql数据转换问题(100分)
- 怎样使查询出来的数据(一个字段)不重复??
- 换服务器:NT4+MSSQL7升级到WIN2K+SQK2K,的问题?
- 误删了一条记录,其中有一个自动编号的字段,如何插入一条记录?
- 提问:如何将'赋给存储过程中的变量...内详 仅剩20分请笑纳...
where not exists(select 1
from 表
where left(MC,2)=left(t.MC,2)
and len(MC)<len(t.MC))
(
BH varchar(20),
MC varchar(10)
)
insert @tb
select '1001AA00000000000002','00101-AAA' union
select '1001AA00000000000001','001-AA' union
select '1012AA000000000008M9','00-A' union
select '1001AA00000000003003','01000-BBB' union
select '1001AA00000000000003','010-BB' union
select '1031AA000000000007JG','01-B' --查询
select * from @tb t
where not exists(select 1
from @tb
where left(MC,2)=left(t.MC,2)
and len(MC)<len(t.MC))
--结果
/*BH MC
-------------------- ----------
1012AA000000000008M9 00-A
1031AA000000000007JG 01-B(所影响的行数为 2 行)
*/
create table #T(BH varchar(20),MC varchar(20))
insert into #T select '1001AA00000000000002','00101-AAA'
insert into #T select '1001AA00000000000001','001-AA'
insert into #T select '1012AA000000000008M9','00-A'
insert into #T select '1001AA00000000003003','01000-BBB'
insert into #T select '1001AA00000000000003','010-BB'
insert into #T select '1031AA000000000007JG','01-B'
--执行查询
select
a.*
from
#T a
where
not exists(select
1
from
#T
where
BH != a.BH
and
left(a.MC,charindex('-',a.MC)-1) like left(MC,charindex('-',MC)-1)+'%')
--输出结果
/*
BH MC
-------------------- -----
1012AA000000000008M9 00-A
1031AA000000000007JG 01-B
*/
--借 vivianfdlpw() 数据
declare @tb table
(
BH varchar(20),
MC varchar(10)
)
insert @tb
select '1001AA00000000000002','00101-AAA' union
select '1001AA00000000000001','001-AA' union
select '1012AA000000000008M9','00-A' union
select '1001AA00000000003003','01000-BBB' union
select '1001AA00000000000003','010-BB' union
select '1031AA000000000007JG','01-B'
--查询
select * from @tb
where len(MC)=4
--结果
BH MC
-------------------- ----------
1012AA000000000008M9 00-A
1031AA000000000007JG 01-B(所影响的行数为 2 行)