如何在数据库中使用函数

问题描述:

尊敬的先生
我通过将逗号分隔开来将值存储在数据库列中,然后创建了一个将值拆分为存储在不同列中的函数,但是我不知道在SQL Server中使用函数的语法.

请帮助我

Dear sir
I stored the values in database columns by separating commas(,) then I made a function to split the values to stored in different columns, but I don''t know the syntax of using function in sql server.

please help me

select dbo.MyFunctionName(@param1..)


查看此链接

http://www.4guysfromrolla.com/webtech/092105-1.shtml [ ^ ]
see this link

http://www.4guysfromrolla.com/webtech/092105-1.shtml[^]


好吧,示例可能会在SQLServer 2005中为您提供帮助:

创建函数MyFunction()
返回@Tbl表
(
StudentID VARCHAR(255),
SAS_StudentInstancesID INT,
标签VARCHAR(255),
价值货币,
CMN_PersonsID INT
)
AS
开始
插入@Tbl
(
学生证,
SAS_StudentInstancesID,
标签,

CMN_PersonsID
)
选择
学生证,
SAS_StudentInstancesID,
标签,

CMN_PersonsID
FROM MyView-MyView从大表中选择(通过联接)相同的列
返回
END

或者您也可以在此链接上进行检查,其中包含您需要的所有详细信息.
http://msdn.microsoft.com/en-us/library/ms186755 (v = SQL.90).aspx [
Well this example might help you out in SQLServer 2005:

CREATE FUNCTION MyFunction ()
RETURNS @Tbl TABLE
(
StudentID VARCHAR(255),
SAS_StudentInstancesID INT,
Label VARCHAR(255),
Value MONEY,
CMN_PersonsID INT
)
AS
BEGIN
INSERT @Tbl
(
StudentID ,
SAS_StudentInstancesID ,
Label ,
Value ,
CMN_PersonsID
)
SELECT
StudentID ,
SAS_StudentInstancesID ,
Label ,
Value ,
CMN_PersonsID
FROM MyView -- where MyView selects (with joins) the same columns from large table(s)
RETURN
END

or you can have a check at this link as well, it has all the details you need.
http://msdn.microsoft.com/en-us/library/ms186755(v=SQL.90).aspx[^]