1. 分割函数:node
--Split 表函数将一个字符串按指定分隔符进行分割,返回一个表。 create function split( @string varchar(255),--待分割字符串 @separator varchar(255)--分割符 )returns @array table(item varchar(255)) as begin declare @begin int,@end int,@item varchar(255) set @begin = 1 set @end=charindex(@separator,@string,@begin) while(@end<>0) begin set @item = substring(@string,@begin,@end-@begin) insert into @array(item) values(@item) set @begin = @end+1 set @end=charindex(@separator,@string,@begin) end set @item = substring(@string,@begin,len(@string)+1-@begin) if (len(@item)>0) insert into @array(item) values(substring(@string,@begin,len(@string)+1-@begin)) return end
http://blog.csdn.net/xiaochunyong/article/details/7974286sql
2005 以上版本XQuery函数
create function func_splitid (@str varchar(max),@split varchar(10)) RETURNS @t Table (c1 int) AS BEGIN DECLARE @x XML SET @x = CONVERT(XML,'<items><item id="' + REPLACE(@str, @split, '"/><item id="') + '"/></items>') INSERT INTO @t SELECT x.item.value('@id[1]', 'INT') FROM @x.nodes('//items/item') AS x(item) RETURN END
执行结果:工具
2. mp_helptextspa
http://blog.csdn.net/xiaochunyong/article/details/7455051 --Siuon --查看存储过程源码 create procedure mp_helptext( @name varchar(255) ) as declare @object_id int, @sourcecode varchar(max), @line varchar(max), @end int, @rn varchar(2), @tab varchar(1) declare @source table( source varchar(max) ) set @rn = char(13)+char(10) set @tab = char(9) select @sourcecode = definition from sys.sql_modules where object_id=object_id(@name) while(charindex(@rn,@sourcecode)!=0) begin set @end=charindex(@rn,@sourcecode) set @line = replace(substring(@sourcecode,1,@end-1),@tab,@tab+@tab) if(charindex('create',@line)<>0 and (charindex('proc',@line)<>0 or charindex('view',@line)<>0 or charindex('function',@line)<>0 or charindex('trigger',@line)<>0)) begin set @line = replace(@line,'create','alter') end insert into @source(source) values(@line) set @end = @end + 2 set @sourcecode = substring(@sourcecode,@end,len(@sourcecode)) end insert into @source(source) values(@sourcecode) select * from @source
SQL Server菜单 工具--选项--环境--键盘: 在这里我是设置的Ctrl+F1键 对应刚刚的存储过程名。.net
http://blog.csdn.net/xiaochunyong/article/details/7455051code