I am using this function:

我正在使用这个功能:

ALTER FUNCTION [dbo].[fncGetCustInfo] (@IShopID int)
RETURNS

@CustomerInfo table (ShopID int, CustID int)

AS
BEGIN

INSERT INTO @CustomerInfo
SELECT  ShopID,
CustomerID
FROM dbo.ShopTbl
WHERE ShopID= @IShopID  
RETURN
END

and this is is my stored procedure:

这是我的存储过程:

ALTER PROC [dbo].[GetCustomerInfo]

@IShopID int 
as
BEGIN

declare @CustomerName varchar(50), @ShopD int, @CustomerID int, @Date date

--Return the customer ids using the function I have created
SELECT @CustomerID = fncGetCustInfo.CustomerID FROM dbo.fncGetCustInfo(@IShopID)
--Set the customer names column using the customer ids I retrived using my function
SELECT @CustomerName = CustomerName
from dbo.CustomerTbl
where CustomerID = @CustomerID

Select @Date = GETDATE()

END

My question is about this line in the sproc:

我的问题是关于sproc中的这一行:

SELECT @CustomerID = fncGetCustInfo.CustomerID FROM dbo.fncGetCustInfo(@IShopID)

Will this return me the CustomerIDs from the table I create in the function called CustomerInfo by calling the function I created earlier

这会通过调用我之前创建的函数从我在名为CustomerInfo的函数中创建的表中返回CustomerID

1 个解决方案

#1


0

The way I do see things my answer will be yes but instead of creating a function to return that result I will embed the function within the proc this way:

我看到的方式我的回答是肯定的,但是我没有创建一个函数来返回结果,而是将这个函数嵌入proc中:

ALTER PROC [dbo].[GetCustomerInfo]
(

@IShopID int 
)
as
BEGIN

declare @CustomerName varchar(50),  @CustomerID int, @Date date   

SET @CustomerID = (SELECT TOP 1 ShopID,CustomerID FROM dbo.ShopTbl WHERE ShopID= @IShopID)


--Set the customer names column using the customer ids I retrived using my     
SELECT @CustomerName = CustomerName
from dbo.CustomerTbl
where CustomerID = @CustomerID

Select @Date = GETDATE()

END

Unless you are going to use the function in a different place but also keep in mind that function can create performance issues.

除非您打算在不同的地方使用该功能,但请记住,该功能可能会产生性能问题。

更多相关文章

  1. MYSQL存储过程,函数,光标
  2. 请问mysql中有没有类似math.max(1,2)这种可以比较两个值中最大值
  3. SQL 函数如何设置参数默认值
  4. 使用不同的条件,在同一个表的一个SQL查询中使用多个聚合函数
  5. PHP OOP - 调用非obj上的成员函数[重复]
  6. 写SQL语句,如何找到部分字段内容一样的两条记录?实现调货的功能
  7. MySQL中实现Oracle里面 rank()over ( PARTITION BY ORDER BY) 分
  8. sqlserver的常用函数
  9. SQLSERVER2005调试存储过程跟函数

随机推荐

  1. Jquery常用技巧和方法收集
  2. 为什么使用observe_field代码不能使用JQu
  3. jQuery——可见性筛选选择器
  4. 如何改变这个js的持续时间
  5. jquery.validate.js使用之自定义表单验证
  6. 在each()函数内部调用多个ajax ..然后在完
  7. 在Ajax请求后添加了自闭标记
  8. Jquery:JS弹出窗口DIV层效果
  9. 如何使用ajax GET或POST方法将数据传递到
  10. 如何从SQL SELECT查询中的c#变量创建jQuer