日期:2014-05-17 浏览次数:20856 次
select *
from [表名]
where quality='c' and left(item,4)='0001'
select * from [表名]
where quality='c' and substring(item,1,4)='0001'
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-24 10:40:32
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise 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]([item] varchar(9),[quality] varchar(1))
insert [huang]
select '000101001','c' union all
select '000101002','c' union all
select '000101003','c' union all
select '000101004','c' union all
select '000101005','f' union all
select '000101006','f' union all
select '000102001','f' union all
select '000102002','f' union all
select '000102003','c' union all
select '000102004','c' union all
select '000102005','c' union all
select '000102006','f' union all
select '000102007','c' union all
select '000202001','f' union all
select '000202002','c' union all
select '000202003','f' union all
select '000202004','c' union all
select '000202005','c' union all
select '000202006','c' union all
select '000202007','f'
--------------开始查询--------------------------
select * from [huang] WHERE quality='c' AND LEFT([item],4)='0001'
----------------结果----------------------------