sqlserver字符串拆分(split)方法汇总 --方法0:动态SQL法declare @s varchar(100),@sql varchar(1000)set @s='1,2,3,4,5,6,7,8,9,10'set @sql='select col='''+ replace(@s,',',''' union all select ''')+''''PRINT @sqlexec (@sql) if exists (select * from dbo.sysobjects where
原文:sqlserver查询所有表的行数的sql语句 select object_name(id),rowcnt from sysindexes where indid<2 and objectproperty(id,'ismsshipped')=0 order by rowcnt desc select a.name, b.rows from sysobjects a inner join sysindexes b on a.id = b.id where a.type = 'u' and b
--字符串分割表函数 ) ) declare @i int; declare @count int; ); ); declare @Index int; )) declare @rowID int; set @str='aaa;bbb;ccc;d;'; set @split=';'; ; set @count=LEN(@str); set @ChildStr=@str; ; while @i<=@count begin set @Index= charindex(@split,@ChildStr
sqlServer 数据库纵横表相互转化 一.纵表转横表: 1.纵表: 2.横表: 3. 代码: select Name as '姓名', end) as '语文', end) as '数学', end) as '英语' from Score group by Name 二.横表转纵表: 1.横表: 2.竖表: 3.代码: select * from( select Name as '姓名','语文' as '语文',Chinise as '分数' from Score1 union all
create TABLE #tempshopt ( shopid varchar(max) ) set @aSql = 'insert into #tempshopt(shopid) select shopid from s_shopid where shopid in ('+@shop+') and n_leix in (4,5) 'exec(@aSql) select @shop=''''+SUBSTRING(shopid,3,LEN(shopid)-2)+'''' from (SELECT
SqlServer获取所有数据库,表,表结构 --获取所有数据库 SELECT * FROM Master..SysDatabases ORDER BY Name --获取test数据库下所有表 use test SELECT name FROM SysObjects Where XType='U' ORDER BY Name --获取test数据库下所有表结构信息 use test then d.name else null end) 表名, a.colorder 字段序号,a.name 字段