SQL 字符串切分函数 (切分为Table)

declare @srcs varchar(8000), @split varchar(10)
set @srcs = 'A,B,C,D,E,F,G,H';
set @split = ',';

declare @Entities TABLE(value varchar(255))
declare @splitlen int
set @splitlen = LEN(@split+'a')-2
while charindex(@split, @srcs)>0
begin
 insert @Entities values(LEFT(@srcs, charindex(@split, @srcs)-1))
 set @srcs = STUFF(@srcs, 1, charindex(@split, @srcs)+@splitlen,'')
end
insert @Entities values(@srcs)

select * from @Entities

 

转自:http://blog.csdn.net/tarmee/archive/2009/07/21/4367059.aspx

 

查询一张表中有多少个字段

 

if object_id('tempdb..#table1') is not null
drop table [dbo].[#table1]
select a.name as [column] into #table1 
from syscolumns a,systypes b 
where a.id=object_id('dbo.Accounts_PermissionCategories') and a.xtype=b.xtype
select COUNT(*)  from [dbo].[#table1]
drop table [dbo].[#table1]

if object_id('tempdb..#table1') is not null

drop table [dbo].[#table1]
select a.name as [column] into #table1 

from syscolumns a,systypes b 

where a.id=object_id('dbo.Accounts_PermissionCategories') and a.xtype=b.xtype    --'dbo.Accounts_PermissionCategories ' 为要查询的表名

select COUNT(*)  from [dbo].[#table1]

drop table [dbo].[#table1]

 

你可能感兴趣的:(table)