id cDatetemp cXz1 12/22-01/19 魔羯座
2 01/20-02/18 水瓶座
3 02/19-03/20 雙魚座............求一条跟据生日最快速获取星座的语句!
2 01/20-02/18 水瓶座
3 02/19-03/20 雙魚座............求一条跟据生日最快速获取星座的语句!
解决方案 »
- sql数据库还原的大难题(在线等)
- 数据库备份作业的问题
- 如何通过代理对sql server操作语句进行审计
- 用NetServerEnum枚举局域网内的SqlServer服务器时,为什么此函数执行慢?
- 连接MS SQL Server服务器地址问题
- 高手们都来救救!请问如何读取timestamp数据类型的值?
- 数据库sa的密码忘记了怎么办?
- 两表合并的问题
- 关于登陆sql 2000的问题!!!
- 關於打印條碼的問題,有水用過ZERBA(斑马)的条码打印机,是用指令的
- 求一数据库语句 再现等。。
- 子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb (id int,cDatetemp varchar(11),cXz varchar(6))
insert into #tb
select 1,'12/22-01/19','魔羯座' union all
select 2,'01/20-02/18','水瓶座' union all
select 3,'02/19-03/20','雙魚座'declare @rq datetimeset @rq='20100203'select * from #tb where @rq between ltrim(year(@rq))+'/'+left(cDatetemp,5) and ltrim(year(@rq))+'/'+right(cDatetemp,5)id cDatetemp cXz
----------- ----------- ------
2 01/20-02/18 水瓶座(1 行受影响)
当生日在 日期1与日期2 之间时(比较时只比较月和日.或者将日期1,日期2,生日三个日期的年设置为同一值,这样就直接比较三个日期),就是对应的星座
if object_id('tempdb.dbo.#') is not null drop table #
create table #(id int, cDatetemp varchar(11), cXz varchar(8))
insert into #
select 1, '12/22-01/19', '魔羯座' union all
select 2, '01/20-02/18', '水瓶座' union all
select 3, '02/19-03/20', '雙魚座'declare @ datetime
set @ = '20100203'
select top 1 cXz from # where right(convert(varchar,@,111),5) >= left(cDatetemp,5) order by cDatetemp
--水瓶座
if object_id('tempdb.dbo.#') is not null drop table #
create table #(id int, cDatetemp varchar(11), cXz varchar(8))
insert into #
select 1, '12/22-01/19', '魔羯座' union all
select 2, '01/20-02/18', '水瓶座' union all
select 3, '02/19-03/20', '雙魚座'declare @ datetime
set @ = '20100118'
if right(convert(varchar,@,111),5)<='01/19'
select '魔羯座'
else
select top 1 cXz from # where right(convert(varchar,@,111),5) >= left(cDatetemp,5) order by cDatetemp
--魔羯座