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 ) 的字符串副本。