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