如何在数据库中使用函数 [英] How to use function in database

查看:72
本文介绍了如何在数据库中使用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生
我通过将逗号分隔开来将值存储在数据库列中,然后创建了一个将值拆分为存储在不同列中的函数,但是我不知道在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[^]


这篇关于如何在数据库中使用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆