我在带有 LINQ to SQL 的存储过程中使用临时表。我将存储过程添加到 Linq to SQL dbml 文件,然后项目出现错误消息
“未知返回类型 - 无法检测到以下存储过程的返回类型。”</p>
当我在存储过程中删除临时表时,返回值很好。
如何在带有 Linq to SQL 的存储过程中使用临时表
我像这样替换诱惑
CREATE TABLE tempTable(
PartsReceivingID INT,
SoPartID INT,
RecvQty INT,
ReturnQty INT
)
像下面这样替换
SELECT @RowCount = count(*)
FROM Parts.studentTempTable
IF @RowCount > 0
BEGIN
TRUNCATE TABLE Parts.studentTempTable;
END
工作版存储过程
ALTER PROCEDURE [dbo].[stp_student_Select_New]
@pSchID as int,
@pCompanyID as int,
@pAgingDate as int,
@pTicketNo as VARCHAR(50),
@pInvoiceNo as VARCHAR(50),
@pDeliveryNo as VARCHAR(50),
@pPartNo as VARCHAR(50)
As
SET NOCOUNT ON
BEGIN
SELECT @RowCount = count(*)
FROM Parts.studentTempTable
IF @RowCount > 0
BEGIN
TRUNCATE TABLE Parts.studentTempTable;
END
===============================================
do something with studentTempTable
===============================================
SELECT
r.Ticketid AS TicketID,
r.SoPartNo AS PartNo ,
p.Description,
r.InvoiceNo as InvoiceNo,
r.InvoiceDate AS InvoiceDate,
DATEDIFF(DY,r.InvoiceDate,GETDATE())as Aging,
r.Qty AS CurrentInventory,
t.ReturnQty AS ReturnQty
FROM Parts.studentTempTable AS t,
Parts.PartsReceiving AS r,
Parts.PartsInfo as p
WHERE t.PartsReceivingID = r.PartsReceivingID
--and i.TicketID = r.TicketID
and p.PartID = r.SoPartID
and t.ReturnQty >0
and DATEDIFF(DY,r.InvoiceDate,GETDATE()) > @pAgingDate
and r.SchID = @pSchID
and r.CompanyID = @pCompanyID
and r.SoPartNo like '%%' + @pTicketNo + '%'
and r.InvoiceNo like '%%' + @pInvoiceNo + '%'
and r.SoPartNo like '%%' + @pPartNo + '%'
--and i.TicketNo like '%%' + @pTicketNo + '%'
--and r.DeliverNo like '%%' + @pDeliveryNo + '%'
Return
END
无 工作版本存储过程
ALTER PROCEDURE [dbo].[stp_student_Select]
@pVendorID as int,
@pCompanyID as int,
@pAgingDate as int,
@pTicketNo as VARCHAR(50),
@pInvoiceNo as VARCHAR(50),
@pDeliveryNo as VARCHAR(50),
@pPartNo as VARCHAR(50)
As
SET NOCOUNT ON
BEGIN
BEGIN TRY
CREATE TABLE tempTable(
PartsReceivingID INT,
SoPartID INT,
RecvQty INT,
ReturnQty INT
)
===============================================
do something with tempTable
===============================================
SELECT
isnull(r.Ticketid,0) AS TicketID,
--i.TicketNo,
r.SoPartNo AS PartNo ,
p.Description,
r.InvoiceNo as InvoiceNo,
--r.DeliveryNo,
r.InvoiceDate AS InvoiceDate,
DATEDIFF(DY,r.InvoiceDate,GETDATE())as Aging,
r.Qty AS CurrentInventory,
t.ReturnQty AS ReturnQty
FROM tempTable AS t,
Parts.PartsReceiving AS r,
--Ticket.TicketInfo as i,
Parts.PartsInfo as p
WHERE t.PartsReceivingID = r.PartsReceivingID
--and i.TicketID = r.TicketID
and p.PartID = r.SoPartID
and t.ReturnQty >0
and DATEDIFF(DY,r.InvoiceDate,GETDATE()) > @pAgingDate
and r.VendorID = @pVendorID
and r.CompanyID = @pCompanyID
and r.SoPartNo like '%%' + @pTicketNo + '%'
and r.InvoiceNo like '%%' + @pInvoiceNo + '%'
and r.SoPartNo like '%%' + @pPartNo + '%'
--and i.TicketNo like '%%' + @pTicketNo + '%'
--and r.DeliverNo like '%%' + @pDeliveryNo + '%'
DROP TABLE temptable
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() as ErrorMessge,
ERROR_NUMBER() AS ErrorNumber
END CATCH
Return
END