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]

 

posted on 2010-02-21 16:57  痴鸟  阅读(1370)  评论(0编辑  收藏  举报