日期:2014-05-19 浏览次数:22817 次
发一个石头的: ------------------------------------ -- Author: happyflystone -- Date:2009-07-20 -- Parameter: @CardString 被查询的串,形如:13300000000-13300001234,13300002230,13300002300 -- @CardNo 要查询的串 -- Return : int 0 -- 不存在于搜索串的范围内 -- 1 -- 存在于 -- 转载请注明出处。更多请访问: http://blog.csdn.net/happyflystone ------------------------------------ Create function IsInCardString(@CardString varchar(8000),@CardNo varchar(11)) returns int as begin declare @temp table(a varchar(200)) declare @i int set @CardString = rtrim(ltrim(@CardString))+',' set @i = charindex(',', @CardString) while @i >= 1 begin insert @temp values(left(@CardString, @i - 1)) set @CardString = substring(@CardString, @i + 1, len(@CardString) - @i) set @i = charindex(',', @CardString) end if exists(select 1 from ( select case when charindex('-',a) > 0 then left(a,11) else a end as s, case when charindex('-',a) > 0 then right(a,11) else a end as e from @temp ) a where @CardNo between s and e) set @i= 1 else set @i= 0 return @i end go declare @CardString varchar(1000) set @CardString = '13300000000-13300001234,13300002230,13300002300,13300002302,13300004101-13300004204,13300004212,13300004310' declare @CardNo varchar(1000) set @CardNo = '13300000001' --存在 select dbo.IsInCardString(@CardString,@CardNo) set @CardNo = '13300001235' --不存在 select dbo.IsInCardString(@CardString,@CardNo) /* ----------- 1 (所影响的行数为 1 行) ----------- 0 (所影响的行数为 1 行) */ drop function IsInCardString 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/happyflystone/archive/2009/07/21/4365264.aspx
------解决方案--------------------
create function udf_GetStar (@ datetime) RETURNS varchar(100) -- 返回日期所属星座 BEGIN RETURN ( --declare @ datetime --set @ = getdate() select max(star) from ( select '魔羯座' as star,1 as [month],1 as [day] union all select '水瓶座',1,20 union all select '双鱼座',2,19 union all select '牡羊座',3,21 union all select '金牛座',4,20 union all select '双子座',5,21 union all select '巨蟹座',6,22 union all select '狮子座',7,23 union all select '处女座',8,23 union all select '天秤座',9,23 union all select '天蝎座',10,24 union all select '射手座',11,22 union all select '魔羯座',12,22 ) stars where dateadd(month,[month] - 1,dateadd(year,year(@) - year(0),0)) + [day] - 1 = ( select max(dateadd(month,[month] - 1,dateadd(year,year(@) - year(0),0)) + [day] - 1) from ( select '魔羯座' as star,1 as [month],1 as [day] union all select '水瓶座',1,20 union a