CREATE FUNCTION dbo.GetCustomers
(
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS BEGIN
SELECT * dbo.GetCustomers
WHERE dbo.GetCustomers.ZIPCODE = ZIPCode
RETURN
END
我不熟悉语法。请帮忙。
答案 0 :(得分:7)
值得猜测参数@ZIPCode
将作为@ZIPCode
进入查询
CREATE FUNCTION dbo.GetCustomers
(
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS
RETURN (
SELECT * FROM dbo.Customers
WHERE dbo.Customers.ZIPCODE = @ZIPCode
)
END
您的第一次尝试WHERE dbo.Customers.ZIPCODE = ZIPCode
与WHERE dbo.Customers.ZIPCODE = dbo.CustomersZIPCode
相同。也就是说,返回所有行
答案 1 :(得分:3)
试试这个
CREATE FUNCTION dbo.GetCustomers (
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS return (SELECT * FROM dbo.Customers WHERE dbo.Customers.ZIPCODE = @ZIPCode)
答案 2 :(得分:1)
当正常的存储过程可以解决问题时,似乎没有任何理由创建一个函数来执行此操作。
CREATE PROCEDURE GetCustomers
@ZIPCode VARCHAR(255)
AS
SELECT * FROM dbo.Customers
WHERE Customers.ZIPCODE = @ZIPCode