SQL 服务器:正在使用临时 table
SQL Server: using Temporary table
我可以通过调用存储过程获得临时 table 的值吗?
由于@productTable 是临时的 table,我可以执行 [dbo.FindProductTotal]
并获取 [dbo.updateProductTotal] 中的值?
在我看来它不起作用。如果没有,有没有办法获得价值
来自在第二个存储过程中执行的第一个临时 table 的结果?真正的编码更复杂,所以我不是不知道只是做简单的插入和更新 tables。我需要知道这种编码方式是否适用于我的实际编码。
ALTER PROCEDURE dbo.FindProductTotal (@ProductID int)
AS
DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
insert into @productTable
select productID, productCode, productDesc, chargeAmt
from product
where region='CA'
--calculate charge here
UPDATE @productTable
SET chargeAmt = (calculation here)
where ProductID = @ProductID
ALTER PROCEDURE dbo.updateProductTotal (@ProductID int)
AS
DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
EXEC dbo.FindProductTotal @ProductID = 123456
UPDATE dbo.Manufacture
SET productChgAmt = p.chargeAmt
FROM @productTable p
WHERE productID = @ProductID
CREATE PROCEDURE dbo.FindProductTotal (@ProductID int)
AS
IF SELECT OBJECT_ID('tempdb..##productTable') IS NULL
DROP TABLE ##productTable
CREATE TABLE ##productTable(subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
--DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
insert into ##productTable
select productID, productCode, productDesc, chargeAmt
from product
where region='CA'
--calculate charge here
UPDATE ##productTable
SET chargeAmt = (calculation here)
where ProductID = @ProductID
CREATE PROCEDURE dbo.updateProductTotal (@ProductID int)
AS
EXEC dbo.FindProductTotal @ProductID = 123456
UPDATE dbo.Manufacture
SET productChgAmt = p.chargeAmt
FROM ##productTable p
WHERE productID = @ProductID
我可以通过调用存储过程获得临时 table 的值吗? 由于@productTable 是临时的 table,我可以执行 [dbo.FindProductTotal] 并获取 [dbo.updateProductTotal] 中的值? 在我看来它不起作用。如果没有,有没有办法获得价值 来自在第二个存储过程中执行的第一个临时 table 的结果?真正的编码更复杂,所以我不是不知道只是做简单的插入和更新 tables。我需要知道这种编码方式是否适用于我的实际编码。
ALTER PROCEDURE dbo.FindProductTotal (@ProductID int)
AS
DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
insert into @productTable
select productID, productCode, productDesc, chargeAmt
from product
where region='CA'
--calculate charge here
UPDATE @productTable
SET chargeAmt = (calculation here)
where ProductID = @ProductID
ALTER PROCEDURE dbo.updateProductTotal (@ProductID int)
AS
DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
EXEC dbo.FindProductTotal @ProductID = 123456
UPDATE dbo.Manufacture
SET productChgAmt = p.chargeAmt
FROM @productTable p
WHERE productID = @ProductID
CREATE PROCEDURE dbo.FindProductTotal (@ProductID int)
AS
IF SELECT OBJECT_ID('tempdb..##productTable') IS NULL
DROP TABLE ##productTable
CREATE TABLE ##productTable(subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
--DECLARE @productTable TABLE (subProductID int, productCode varchar(10), productDesc varchar(25), chargeAmt money)
insert into ##productTable
select productID, productCode, productDesc, chargeAmt
from product
where region='CA'
--calculate charge here
UPDATE ##productTable
SET chargeAmt = (calculation here)
where ProductID = @ProductID
CREATE PROCEDURE dbo.updateProductTotal (@ProductID int)
AS
EXEC dbo.FindProductTotal @ProductID = 123456
UPDATE dbo.Manufacture
SET productChgAmt = p.chargeAmt
FROM ##productTable p
WHERE productID = @ProductID