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