0
从VB 2008调用此存储过程。试图用select * from #temptable
的结果填充DataGridView
。但是,存储过程返回项目的结果集和最后一条SQL语句的结果集。我不想为@Item
返回任何东西。只希望在主要声明中使用它。获取比我希望从SQL Server存储过程更多的结果集
ALTER PROCEDURE [dbo].[spGetItem2]
@ScanData NVARCHAR(50),
@RecordCount INT OUTPUT
AS
SET NOCOUNT ON
Begin
DECLARE @Item char(20)
SELECT i.Item
FROM dbo.Inv_Item i
WHERE i.Item = @ScanData
Set @RecordCount = @@RowCount
if @@RowCOunt > 0
Set @Item = @Scandata
Else
SELECT @Item = Inv_Item.Item
FROM Inv_UPC
INNER JOIN Inv_Item ON Inv_UPC.Item = Inv_Item.Item
WHERE upc = @Scandata
--Set @Item = @Item
Set @RecordCount = @@RowCount
END
Begin
SELECT
Inv_Item_Location_Detail.Area, Inv_Item_Location_Detail.Location,
Inv_Item_Location_Detail.Item, Inv_Item.[Description],
Inv_Item_Location_Detail.[Level], Inv_item_levels.[levelDescription],
Inv_Item_Location_Detail.GID,
Count(Inv_Item_Location_Detail.Item) as QTY
INTO
#TempTable
FROM
Inv_Item_Location_Detail
LEFT OUTER JOIN
Inv_Item ON Inv_Item_Location_Detail.Item = Inv_Item.Item
LEFT OUTER JOIN
Inv_Item_Levels ON Inv_Item_Location_Detail.[Level] = Inv_Item_Levels.[Level]
AND Inv_Item_Location_Detail.Item = Inv_Item_Levels.ItemNumber
WHERE
(Inv_Item_Location_Detail.Item = @Item)
GROUP BY
Inv_Item_Location_Detail.Area, Inv_Item_Location_Detail.Location,
Inv_Item_Location_Detail.Item, Inv_Item_Location_Detail.[Level],
Inv_Item_Location_Detail.GID, Inv_Item.[Description],
Inv_item_levels.[levelDescription]
End
Select * from #Temptable
- 首先返回@Item的值。 - 然后它返回一个结果集,这是我正在寻找的。
使用'if exists(select ...)'而不是选择并检查'@@ rowcount'。为什么要插入临时表然后从中进行选择而不是直接选择? –