SQL 函数和存储过程(待续)

C#调用数据库自定义函数:


<一>:


追加字符窜:

StrSql="update  WASTMA_Borrow  set  AB010=AB010+','+@AB010 where AB002=@AB002"

      


分割字符窜:


 strSql.Append("select AB001,AB002,AB003,AB004,AB005,AB006,AB007,AB008,AB009,AB011,AB012,AB013,AB014,AB015,AB016,AB017,C.AC002, ");


 strSql.Append(" sa1.Get_SegStr(AB010) as AB010");


USE [XMDEV]
GO
/****** Object:  UserDefinedFunction [sa1].[Get_SegStr]    Script Date: 09/07/2012 09:09:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
ALTER FUNCTION  [sa1].[Get_SegStr]
(
@Str  varchar(50)

)
RETURNS  varchar
AS
BEGIN
-- Declare the return variable here
DECLARE @str1  varchar 


-- Add the T-SQL statements to compute the return value here

select substring(@Str,charindex(',',@Str)+1,1)  from WASTMA_Borrow
 
-- Return the result of the function

RETURN @str1




END



substring:返回字符串的一部分----substring(expression,start,length),返回指定字符串



charindex:在一段字符串中搜索字符或者字符串----charindex(expression1,expression2[,start_location]),返回索引位置(int 类型)


LTrim、RTrim 和 Trim 函数的区别

返回不带 前导空格  ( LTrim )、后续空格 ( RTrim ) 或前导与后续空格 ( Trim ) 的字符串副本。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值