zoukankan      html  css  js  c++  java
  • sql 函数

    正确写法:
    ALTER FUNCTION [dbo].[uf_GetContractPartyName] ( @ContractPartyID as uniqueidentifier ) RETURNS varchar(300) AS BEGIN DECLARE @Ret varchar(300) SELECT @Ret =PartyName FROM tbl_biz_ContractPartyInfo WHERE ContractPartyID = @ContractPartyID RETURN @Ret END

      

    错误写法:
    ALTER FUNCTION [dbo].[uf_GetContractPartyName] ( @ContractPartyID as uniqueidentifier ) RETURNS @Ret varchar(300) AS BEGIN --DECLARE @Ret varchar(300) SELECT @Ret =PartyName FROM tbl_biz_ContractPartyInfo WHERE ContractPartyID = @ContractPartyID RETURN --@Ret END

    sql变量使用前必须declare,临时表使用前不需要declare

      

    /******************************************************************************
    **		Name: ufn_Split
    **		Desc: 拆分字符串
    **
    **              
    **		Return Values:
    ** 				
    **		Parameters:	
    **		Auth: 
    **		Date:2008-10-24
    *******************************************************************************/
    ALTER function [dbo].[ufn_Split]
    (
    	@String varchar(max),				-- 要拆分的字符串
    	@Key varchar(50)					-- 关键字
    )
    returns @sValues table(sIndex int identity(1,1), sValue varchar(max) )
    as
    begin
    	-- 索引及当前值
    	declare @KeyIndex int
    	declare @CurrentValue varchar(500)
    
    	set @string = RTrim(LTrim(@String))
    	
    	-- 拆分
    	set @KeyIndex = charindex(@Key,@string)
    
    	while @KeyIndex <> 0
    	begin
    		set @CurrentValue = substring(@String,1,@KeyIndex-1)
    
    		insert into @sValues(sValue) values (@CurrentValue)
    
    		set @String = substring(@String, @KeyIndex+1, len(@String)- @KeyIndex)
    
    		set @KeyIndex = charindex(@Key, @String)
    	end
    
    	insert into @sValues(sValue) values (@String)
    
    	-- 返回拆份结果
    	return
    end

    sql变量使用前必须declare,临时表使用前不需要declare

      

  • 相关阅读:
    jQuery ajax解析xml文件demo
    Jquery ajax传递xml方式在ie8下兼容问题
    Ajax 跨域请求
    【leetcode刷题笔记】Maximal Rectangle
    【leetcode刷题笔记】Substring with Concatenation of All Words
    【leetcode刷题笔记】Largest Rectangle in Histogram
    【leetcode刷题笔记】Decode Ways
    【leetcode刷题笔记】3Sum Closest
    【leetcode刷题笔记】3Sum
    【leetcode刷题笔记】Divide Two Integers
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/7609653.html
Copyright © 2011-2022 走看看