CREATE FUNCTION dbo.GetCustomers
(
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS BEGIN
SELECT * dbo.GetCustomers
WHERE dbo.GetCustomers.ZIPCODE = ZIPCode
RETURN
END
我不熟悉語法。請幫忙。函數返回錶行
CREATE FUNCTION dbo.GetCustomers
(
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS BEGIN
SELECT * dbo.GetCustomers
WHERE dbo.GetCustomers.ZIPCODE = ZIPCode
RETURN
END
我不熟悉語法。請幫忙。函數返回錶行
這本來是值得猜測的參數@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
。也就是說,返回所有行
試試這個
CREATE FUNCTION dbo.GetCustomers (
@ZIPCode VARCHAR(255)
)
RETURNS TABLE
AS return (SELECT * FROM dbo.Customers WHERE dbo.Customers.ZIPCODE = @ZIPCode)
似乎有不被任何好的理由來創建一個函數來做到這一點,當一個正常的存儲過程將這樣的伎倆。
CREATE PROCEDURE GetCustomers
@ZIPCode VARCHAR(255)
AS
SELECT * FROM dbo.Customers
WHERE Customers.ZIPCODE = @ZIPCode
如果您指出了更改的內容,即'ZIPCode' - >'@ ZIPCode',會有幫助。 –
匿名downvote? – gbn
@gbr即時通訊製作一個正則表達式的搜索模式,並與它進行比較。但我唯一的問題是重演它。我會在我的代碼上改變它。 – noname