Create function getbyID ( @id int )
Returns table
as
return(
select * from Products where
ProductID=@id+10)
上面的函数会重新生成产品ID大于10的产品的所有记录。
与CROSS APPLY一起使用时如下
select o.* from [Order Details] o
CROSS APPLY getbyID(o.ProductID) P
我在结果中得到一些小于10的productID,这是不可能的。
该示例使用NORTWIND数据库示例随处可用。
ORDER DETAILS表和PRODCUTS表由ProductID链接
Select* from getbyID (1) gives result below
当调用UDF时(如上所述)结果显示一些productID< 10
你能看到错误在哪里吗?
答案 0 :(得分:3)
如果您希望函数只返回ProductID大于10的产品,则应将此检查添加到where子句中。例如:
@app.route("/api/users")