我有一个存储过程,
我想在列HAVING
和IsUserFruitEater
中使用IsUserOnSite
子句,但它表示列不存在。
不确定如何使用列,必须有办法使用存储过程结果的列...
ALTER procedure [dbo].[Risks_GetFruitCratesForUser]
(
@UserID VARCHAR(200),
@URLFilter varchar(256)
)
AS
SELECT DISTINCT
Fruits.*
,FruitsCrate.* dbo.IsUserRegularFruitEater(@UserID, FruitsCrate.FutureID) AS
IsUserFruitEater
,dbo.IsUserOnSite(@UserID, FruitsCrate.FID) AS IsUserOnSite
,COALESCE(doThis.deeraw, - 1) AS deeraw
,COALESCE(doThat.HeroSheema, - 1) AS HeroSheema
,Jootey.deeraw * Jootey.HeroSheema AS BigBang
FROM someTable....
WHERE blahblah NOT NULL
AND blahblah2 LIKE "abc"
HAVING Min(IsUserFruitEater) > 0
OR Min(IsUserOnSite) > 0
答案 0 :(得分:1)
使用子查询和where
子句:
SELECT t.*
FROM (SELECT DISTINCT Fruits.*, FruitsCrate.*
dbo.IsUserRegularFruitEater(@UserID, FruitsCrate.FutureID) AS IsUserFruitEater,
dbo.IsUserOnSite(@UserID, FruitsCrate.FID) AS IsUserOnSite,
COALESCE(doThis.deeraw, -1) As deeraw , COALESCE(doThat.HeroSheema, -1) As HeroSheema,
Jootey.deeraw * Jootey.HeroSheema As BigBang
From someTable....
WHERE blahblah NOT NULL AND blahblah2 LIKE "abc"
) t
WHERE IsUserFruitEater > 0 or IsUserOnSite > 0;
我不确定min()
的含义。您没有group by
,这是使用having
子句的问题。