sql - Right way to subtract in a stored procedure -


i have following query in stored procedure

declare @i int declare @tenpercent int declare @rowscount int  set @tenpercent =10 set @i = 1  select      @i, dbo.tblvegetationtype.vegtypecode, dbo.tblvegetationtype.vegtypename      dbo.tblvegetationtype  inner join      dbo.tblvegtypevegformationlink on dbo.tblvegetationtype.vegtypeid = dbo.tblvegtypevegformationlink.vegtypeid inner join      tblcmavegtypelink on dbo.tblvegetationtype.vegtypeid = dbo.tblcmavegtypelink.vegtypeid        dbo.tblvegetationtype.percentagecleared >= (@percentcleared - @tenpercent)     , dbo.tblvegtypevegformationlink.vegetationformationid = @vegetationformationid     , dbo.tblcmavegtypelink.cmaid = @cmaid  

i have following condition

dbo.tblvegetationtype.percentagecleared >= (@percentcleared - @tenpercent) 

what trying here: if percentcleared 60% want query pick list 50 %.

so add set @tenpercent = 10 , subtract condition.

is right way do?

another way of writing query can be:

select @i,        vt.vegtypecode,        vt.vegtypename dbo.tblvegetationtype vt inner join dbo.tblvegtypevegformationlink vtvf on vt.vegtypeid = vtvf.vegtypeid inner join tblcmavegtypelink cvt on vt.vegtypeid = cvt.vegtypeid 1= case when  @percentcleared >= 60 ,  vt.percentagecleared <= 50 1 -- can add condition when @percentcleared < 60 values of    -- vt.percentagecleared considered         when  @percentcleared < 60 ,  vt.percentagecleared <= 50 1         end , vtvf.vegetationformationid = @vegetationformationid , cvt.cmaid = @cmaid  

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -