如何写函数的视图? [英] how to write view for function?

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

问题描述

我写了一些函数。我需要查看该函数如何为此编写查询?

例如我的函数名称和查询

  ALTER   FUNCTION  [dbo]。[Get_City] 

- 在此处添加函数的参数
@ Id int

RETURNS TABLE
AS
返回

- 在此处添加带参数引用的SELECT语句
SELECT * FROM CITY





如何写这个视图请回答

解决方案

I请求你参考这个链接并了解如何为SQL函数编写视图



http://stackoverflow.com/questions/2877247/using-a-table-value-function-inside-a- view-in-sql-server [ ^ ]




您可以在返回表格的Function中轻松传递参数数据这是一个很好的方法,但传递参数到视图略有不同,使用这种方法也是不可取的,



只是为了你的知识分享



您可以使用此方法将参数传递给您的视图,然后传递给您的函数..



set context_info 2



从mas中选择convert(int,convert(binary(4),context_info)) ter.dbo.sysprocesses

其中

spid = @@ spid)







http://stackoverflow.com/ questions / 4498364 / create-parameterized-view-in-sql-server-2008



问候

Mubin

i have wrote some functions. i need view for that functions how to write query for that?
like example my function name and query

ALTER FUNCTION  [dbo].[Get_City]
(	
	-- Add the parameters for the function here
	@Id int
)
RETURNS TABLE 
AS
RETURN 
(
	-- Add the SELECT statement with parameter references here
	SELECT * FROM CITY
 )



how to write view for this please answer

解决方案

I would request you to refer this link and get to know how to write view for SQL funtion

http://stackoverflow.com/questions/2877247/using-a-table-value-function-inside-a-view-in-sql-server[^]


Hi ,
You can pass parameter easily in Function which returns table data this is good approach, but to pass parameter to view is slightly different and using this method is also not advisable,

just sharing for your knowledge

You can use this method to pass your parameter to your view an then to your function..

set context_info 2

select convert(int, convert(binary(4), context_info)) from master.dbo.sysprocesses
where
spid = @@spid)



http://stackoverflow.com/questions/4498364/create-parameterized-view-in-sql-server-2008

Regards
Mubin


这篇关于如何写函数的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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