select * from grade where 学号 BETWEEN 'B0001' AND 'B0008'
--我是来蹭分的 select * from grade where 学号 BETWEEN 'B0001' AND 'B0008'
select * from grade where 学号 between 'B0001' and 'B0008'
select * from grade where 学号 like 'B00[1-8]'
select * from grade where 学号 between 'B0001' and 'B0008' select * from grade where 学号 >= 'B0001' and 学号 <='B0008'
select * from grade where 学号 between 'B0001' and 'B0008' select * from grade where 学号 >= 'B0001' and 学号 <='B0008'
select * from grade where cast(right(学号,1) as int) between 1 and 8 select * from grade where cast(right(学号,1) as int) >= 1 and 学号 <=8
select * from grade where cast(right(学号,1) as int) between 1 and 8 select * from grade where cast(right(学号,1) as int) >= 1 and cast(right(学号,1) as int) <=8
这个简单些,字符串之间也可以用”between“,"<",">"?
---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2009-10-17 10:05:43 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[grade] if object_id('[grade]') is not null drop table [grade] go create table [grade]([学号] varchar(5),[姓名] varchar(2)) insert [grade] select 'B0001','aa' union all select 'B0002','bb' union all select 'B0003','cc' union all select 'B0004','dd' union all select 'B0005','ee' union all select 'B0006','ff' union all select 'B0007','gg' union all select 'B0008','hh' union all select 'B0009','ii' --------------开始查询-------------------------- select * from grade where 学号 between 'B0001' and 'B0008' select * from grade where 学号 >= 'B0001' and 学号 <='B0008' select * from grade where cast(right(学号,1) as int) between 1 and 8 select * from grade where cast(right(学号,1) as int) >= 1 and cast(right(学号,1) as int) <=8 ----------------结果---------------------------- /* (9 行受影响) 学号 姓名 ----- ---- B0001 aa B0002 bb B0003 cc B0004 dd B0005 ee B0006 ff B0007 gg B0008 hh(8 行受影响)学号 姓名 ----- ---- B0001 aa B0002 bb B0003 cc B0004 dd B0005 ee B0006 ff B0007 gg B0008 hh(8 行受影响)学号 姓名 ----- ---- B0001 aa B0002 bb B0003 cc B0004 dd B0005 ee B0006 ff B0007 gg B0008 hh(8 行受影响)学号 姓名 ----- ---- B0001 aa B0002 bb B0003 cc B0004 dd B0005 ee B0006 ff B0007 gg B0008 hh(8 行受影响) */
select * from grade where 学号 BETWEEN 'B0001' AND 'B0008'
select * from grade where 学号 >= 'B0001' and 学号 <='B0008'
select * from grade where 学号 >= 'B0001' and 学号 <='B0008'
select * from grade where cast(right(学号,1) as int) >= 1 and 学号 <=8
select * from grade where cast(right(学号,1) as int) >= 1 and cast(right(学号,1) as int) <=8
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-10-17 10:05:43
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[grade]
if object_id('[grade]') is not null drop table [grade]
go
create table [grade]([学号] varchar(5),[姓名] varchar(2))
insert [grade]
select 'B0001','aa' union all
select 'B0002','bb' union all
select 'B0003','cc' union all
select 'B0004','dd' union all
select 'B0005','ee' union all
select 'B0006','ff' union all
select 'B0007','gg' union all
select 'B0008','hh' union all
select 'B0009','ii'
--------------开始查询--------------------------
select * from grade where 学号 between 'B0001' and 'B0008'
select * from grade where 学号 >= 'B0001' and 学号 <='B0008'
select * from grade where cast(right(学号,1) as int) between 1 and 8
select * from grade where cast(right(学号,1) as int) >= 1 and cast(right(学号,1) as int) <=8
----------------结果----------------------------
/*
(9 行受影响)
学号 姓名
----- ----
B0001 aa
B0002 bb
B0003 cc
B0004 dd
B0005 ee
B0006 ff
B0007 gg
B0008 hh(8 行受影响)学号 姓名
----- ----
B0001 aa
B0002 bb
B0003 cc
B0004 dd
B0005 ee
B0006 ff
B0007 gg
B0008 hh(8 行受影响)学号 姓名
----- ----
B0001 aa
B0002 bb
B0003 cc
B0004 dd
B0005 ee
B0006 ff
B0007 gg
B0008 hh(8 行受影响)学号 姓名
----- ----
B0001 aa
B0002 bb
B0003 cc
B0004 dd
B0005 ee
B0006 ff
B0007 gg
B0008 hh(8 行受影响)
*/