SQL-Server: using an if in the where operator -
i'm creating stored procedure gets values table stores projects funding (their id, goal , they've received far) , proc return either project id's have been funded or haven't given parameter @querytype
, don't know how put if condition in where
, i've ever used them in select
portion of statement.
this have far gives me incorrect syntax
on first case:
--create proc projects.getfundedprojects -- projects have reached goal create proc projects.getfundedprojects (@querytype int ) begin select * stats.fundedprojectstoday case when @querytype = 1 -- projects reached goal aureceived=>projectgoal when @querytype = 2 -- projects have not been funded aureceived<projectgoal end --end case end -- end proc
use mutually exclusive conditions each @querytype
value:
select * stats.fundedprojectstoday (@querytype = 1 , aureceived >= projectgoal) or (@querytype = 2 , aureceived < projectgoal)
by way, greater or equal operator written >=
, not =>
.
Comments
Post a Comment