SQL 数字分割的字符串


patindex( '%[^-^0-9]% ',col)=0 
:表示包含正数或者负数。或者0 
即表示,数字的字段!
select * from tb where patindex('%[^0-9]%',col) = 0

select * from 表名 where isnull(字段名,'')<>''
同时排除空值和null的情况


select coopmedcode,patientname,sum(freefee) as total   from 
(select coopmedcode,patientname,freefee from dbo.o_CbZyBxDj                                       
union all
select coopmedcode,patientname,freefee from dbo.s_CbZyBxDj ) a  group by coopmedcode,patientname order by total desc

update PAS_D set _enable='Y' where ((fun_id='A1A' and pas_m_id<>'A1') or (fun_id='A1A' and pas_m_id<>'A2'))不等


delete from tb  
where 车牌号 in (select  车牌号  from tb  group  by  车牌号  having  count(车牌号) > 1)
 id not  in (select min( id)  from tb  group  by  车牌号  having  count(车牌号) > 1) 

 
 select * from syscolumns    数据库所有列
 
 
 set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

--select dbo.[Get_StrArrayStrOfIndex] ('123,1231,12',',',1)
ALTER function [dbo].[Get_StrArrayStrOfIndex]
(
 @str varchar(1024),  --要分割的字符串
 @split varchar(10),  --分隔符号
 @index int --取第几个元素
)
returns varchar(1024)
as
begin
 declare @location int
 declare @start int
 declare @next int
 declare @seed int 
 set @str=ltrim(rtrim(@str))
 set @start=1
 set @next=1
 set @seed=len(@split)
 
 set @location=charindex(@split,@str)
 while @location<>0 and @index>@next
 begin
   set @start=@location+@seed
   set @location=charindex(@split,@str,@start)
   set @next=@next+1
 end
 if @location =0 select @location =len(@str)+1 
--这儿存在两种情况:1、字符串不存在分隔符号 2、字符串中存在分隔符号,跳出while循环后,@location为0,那默认为字符串后边有一个分隔符号。
 
 return substring(@str,@start,@location-@start)
end

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM