我想使用我的表變量「@Customers」的變量,如「@Customers.Name」,我試過它像:Customers.Name或@ Customers.Name,但都顯示錯誤,請建議如何使用變量?如何使用傳遞給另一個存儲過程的表的變量?
CREATE TYPE [dbo].[TableType] AS TABLE(
[CustomerID] [int] NOT NULL,
[Name] [varchar](255) NULL,
[City] [varchar](50) NULL,
[State] [char](2) NULL,
[Zipcode] [varchar](20) NULL
)
GO
ALTER PROCEDURE sp_GetCustomers
AS
BEGIN
DECLARE @Customers AS TableType
INSERT INTO @Customers(CustomerID,Name,City,State,ZipCode)
SELECT C.CustomerID,C.FirstName + ' ' + C.LastName,A.City,A.State,A.ZipCode
FROM Customers C INNER JOIN CustomerAddress A ON C.CustomerID=A.CustomerID
EXEC sp_GetCustomersWithAddresses @Customers
END
go
CREATE PROCEDURE sp_GetCustomersWithAddresses
@Customers TableType READONLY
AS
BEGIN
SELECT * FROM @Customers where @Customers.Name="XYZ";
END