如何使用存储过程返回视图数据
嗨朋友们,要求是使用存储过程我应该从视图返回所有值。
目前我们有一个存储过程来返回给定表中的所有值,
CREATE PROCEDURE [dbo].[SuperGas_GetAllEmployees]
AS
BEGIN
SELECT [Employee ID]
,[First Name]
,[Last Name]
,[Group]
,[Location]
,[DOB]
,[DOJ]
,[Manager]
,[Projects]
,[Phone]
,[Extension]
FROM [SuperGas].[dbo].[Employee]
END
我们通过连接两个名为 ExpenseView 的表创建了一个视图,
CREATE VIEW [dbo].[ExpenseView] AS
SELECT Emp.[Employee ID], Emp.[First Name],Emp.[Last Name],Emp.Manager, Ep.[Expense Type],Ep.[Expense Amount],Ep.[Expense Date]
FROM [Employee Expense] as Ep
FULL JOIN Employee as Emp
ON EP.[Employee ID] = Emp.[Employee ID]
现在的问题就像第一个存储过程一样,如何返回所有列使用存储过程的上述视图(费用)。 我们尝试使用与第一个程序相同的方式;但是,查询中未识别查看 ExpenseView。
历史,
从我之前的问题中我知道,将视图与存储过程一起使用是不好的。
然而,我们的应用程序使用下面的 C# 代码使用存储过程从数据库获取数据,
string spName = "SuperGas_GetAllEmployees";
DataSet ds = GetDatasetFromAdapter(spName);
更改此方式需要大量时间和额外资源来进行编码。因此,有什么方法可以返回整个视图(就像我们在给定的表过程 SuperGas_GetAllEmployees 中所做的那样),以便我可以利用当前代码本身。
感谢您提供的所有帮助
编辑...
CREATE PROCEDURE [dbo].[SuperGas_GetAllExpenseView]
AS
BEGIN
SELECT [Employee ID]
,[First Name]
,[Last Name]
,[Manager]
,[Expense Type]
,[Expense Amount]
,[Expense Date]
FROM [SuperGas].[dbo].[ExpenseView]
END
GO
,我在“费用类型”、“费用金额”、“费用日期”字段和视图名称 ExpenseView 中收到错误,
请帮助我
Hi friends the requirement is that using a stored procedure I should return all the value from a view.
Currently we are having a storedprocedure to return all the values from a table as given,
CREATE PROCEDURE [dbo].[SuperGas_GetAllEmployees]
AS
BEGIN
SELECT [Employee ID]
,[First Name]
,[Last Name]
,[Group]
,[Location]
,[DOB]
,[DOJ]
,[Manager]
,[Projects]
,[Phone]
,[Extension]
FROM [SuperGas].[dbo].[Employee]
END
We have created a view by joining two tables named ExpenseView as given,
CREATE VIEW [dbo].[ExpenseView] AS
SELECT Emp.[Employee ID], Emp.[First Name],Emp.[Last Name],Emp.Manager, Ep.[Expense Type],Ep.[Expense Amount],Ep.[Expense Date]
FROM [Employee Expense] as Ep
FULL JOIN Employee as Emp
ON EP.[Employee ID] = Emp.[Employee ID]
Now the question here is like in the first stored procedure, how can I return all the columns of the above view (Expense) using a stored procedure.
We tried using the same way as the first procedure; however the View ExpenseView is not identified in the query.
History,
From my previous question I came to know, it is not good to use view with a Storedprocedure.
However our application is using the below c# code to get data from the Database using a stored Procedure,
string spName = "SuperGas_GetAllEmployees";
DataSet ds = GetDatasetFromAdapter(spName);
Changing this needs extensive time and extra resources for the coding. Hence is there any way I can return the entire View (Like what we did in the given procedure SuperGas_GetAllEmployees for Tables) So that I can make use of current Code itself.
Thank you for all your Help
Editing ....
CREATE PROCEDURE [dbo].[SuperGas_GetAllExpenseView]
AS
BEGIN
SELECT [Employee ID]
,[First Name]
,[Last Name]
,[Manager]
,[Expense Type]
,[Expense Amount]
,[Expense Date]
FROM [SuperGas].[dbo].[ExpenseView]
END
GO
Here I am getting error for the fields Expense Type, Expense Amount, Expense Date and for the view name ExpenseView
Please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上视图是在哪里创建的?在您的存储过程中,您使用
FROM [SuperGas].[dbo].[ExpenseView]
您能否确保视图位于
[SuperGas]
内部Actually where the view is created? In your stored procedure you use
FROM [SuperGas].[dbo].[ExpenseView]
Could you please ensure that the view is inside of
[SuperGas]