5
這是我的sql查詢。我可以用什麼來代替#sql表中的sql函數
CREATE FUNCTION UF_GetOrderProducts
(
@OrderId int
)
RETURNS VARCHAR(500)
AS
BEGIN
SELECT Identity(int,1,1) ID, ProductId INTO #Temp FROM OrderProduct WHERE OrderId = @OrderId
Declare @Id int,
@Count int,
@LoopCount int,
@ProductList VARCHAR(500),
@ProductListTemp VARCHAR(500)
SET @Count = (Select Count(*) From #Temp)
SET @LoopCount = 1
SET @ProductList = ''
WHILE @LoopCount <= @Count
BEGIN
SET @ProductListTemp =(SELECT Name FROM Product WHERE ProductId =(Select ProductId from #Temp Where ID = @LoopCount))
SET @ProductList [email protected] + '<br/>'
Set @[email protected] + 1
END
DROP TABLE #Temp
RETURN @ProductList
END
GO
我必須在#Temp表中循環。你有什麼其他的建議?