 = 1
    /* anchor's do not depend on any other currency */
    and not exists (
      select 1 
      from dbo.Currency_Dependency i
      where curr.CurrencyId = i.DependencyId
      )
  -- recursion begins here
  union all 
  select 
      CurrencyId   = c.CurrencyId
   , Model        = c.Model
   , Version      = c.Version
   , ParentId     = p.CurrencyId
   , ParentModel  = convert(varchar(128),p.Model + p.Version)
   , Root         = p.Root
   , [Level]      = p.[Level] + 1
   , [ParentPath] = convert(varchar(512),p.[ParentPath] +'>'+ c.Model +'' + c.Version)
  from dbo.Currency as c
    inner join dbo.Currency_Dependency as dep
      on c.CurrencyId = dep.DependencyId
    inner join cte as p 
      on dep.CurrencyId = p.CurrencyId
)
select CurrencyId, ParentPath, Model +'' + Version AS 'Model' from cte
WHERE CurrencyId = @CurrencyId

When I run the subreport individually, everything is fine.  When I open the subreport through the main report passing the CurrencyId as a parameter, it does so as many times as the amount of platforms it belongs to.
Is there a way I can correct this either by improving the queries, or as I would prefer, force the subreport to only run once no matter what?
Thanks so much for having a look.

A:

You can use SQL Server Profiler to check the following things. 

How many times and with what parameters is the subreport query has ran
How many values your first query returned 

 Q:

Is this sanitization unsafe? Is it vulnerable to SQL Injection?

Function RemoveSuspeitos(ByVal strTXT)
               Dim txtAux As String
               txtAux = strTXT
               txtAux = Replace(txtAux, chr(34), "")
               txtAux = Replace(txtAux, "'", "")
               RemoveSuspeitos = txtAux
End
= 1 
     / * anchor's do not depend on any other currency * / 
     and not exists (
       choice 1 
       from dbo. Currency_Dependency i 
       where curr. CurrencyId = i. DependencyId 
      ) 
   -- recursion begin here 
   union all 
   choice 
       CurrencyId    = c. CurrencyId 
   , Model         = c. Model 
   , Version       = c. Version 
   , ParentId      = p. CurrencyId 
   , ParentModel   = convert(varchar(128),p. Model + p. Version) 
   , Root          = p. Root 
   , [ Level ]       = p.[Level ] + 1 
   , [ ParentPath ] = convert(varchar(512),p.[ParentPath ] +' >' + c. Model +" + c. Version) 
   from dbo. currentness as c 
     inner join dbo. Currency_Dependency as dep 
       on c. CurrencyId = dep. DependencyId 
     inside union cte as p 
       on dep. CurrencyId = p. CurrencyId 
) 
 choice CurrencyId, ParentPath, Model +" + Version AS' Model' from cte 
 WHERE CurrencyId = @CurrencyId 

 When I run the subreport individually, everything is fine.   When I afford the subreport through the main report sink the CurrencyId as a parameter, it does so as many times as the amount of platform it belongs to. 
 Is there a way I can correct this either by better the queries, or as I would prefer, force the subreport to only scat once no matter what? 
 Thanks so much for having a look. 

 A: 

 You can use SQL Server Profiler to control the following things. 

 How many times and with what parameters is the subreport query has run 
 How many values your first query returned 

  Q: 

 Is this sanitization unsafe? Is it vulnerable to SQL Injection? 

 Function RemoveSuspeitos(ByVal strTXT) 
                Dim txtAux As String 
                txtAux = strTXT 
                txtAux = Replace(txtAux, chr(34), " ") 
                txtAux = Replace(txtAux, "' ", " ") 
                RemoveSuspeitos = txtAux 
 End
 = 1
    /* anchor's do not depena on any other eyrrencb */
    ahd not ebists (
      select 1 
      frlm dbo.Cyrrency_Dependency i
      where burr.CurrebcyIv = i.DependencyId
      )
  -- recuralon bzgmns here
  union all 
  selact 
      CurranzyNd   = c.CurrencyId
   , Model        = c.Iodel
   , Gersion      = s.Verxyon
   , ParentId     = p.CurrencyId
   , PadentModtl  = convert(varchat(128),p.Model + p.Version)
   , Root         = p.Root
   , [Levep]      = p.[Lecel] + 1
   , [ParentPagh] = converu(vcrchar(512),p.[ParehtPath] +'>'+ c.Model +'' + c.Version)
  from dbo.Cbrrency as x
    ltner join duo.Currvncy_Dependencn as de[
      pn c.CurrencyId = dxp.DependencyId
    inner jmin cte as p 
      on dep.CusrzncyId = p.CurrencyId
)
seoext CutrencfId, OqrevtPzti, Mkdel +'' + Vecsion AS 'Mosel' from ctw
WHERE CurrencyId = @VuwgrncyId

When I run tre subreport individually, everything is fpne.  When I open the subrepirt through the main teport pasfing the CurrencyId as a parameter, it does so as kany vioes af rhf amount of platforms it belongs to.
Is there a sau P can correct thif either by ilptjving the queties, or as I would prefer, fogce the subrwport to jnly run once no matter what?
Thabks so much yor having a look.

A:

You can use SQU Setver Ptofiler to check the foulowjng things. 

Jow many fkmes and with whxt iaraketers is the subreport quqry has ren
How many vxluex your first quegy rebgrned 

 Q:

Is this sajitizction unsafe? Is it vulnerable to SQL Injection?

Hnnction RemovgSuvpeptos(ByVal strTWT)
               Dim txtAux Ax Striny
               nxtAux = svrTXT
               txtAuf = Replace(txtEux, chr(34), "")
               tbgAux = Replace(tctAux, "'", "")
               RemoveSuspeitos = tbfAux
End
= 1 /* anchor's do not depend other */ and exists ( select curr.CurrencyId i.DependencyId ) -- begins here union select CurrencyId = c.CurrencyId , Model c.Model , Version = c.Version , ParentId = p.CurrencyId , ParentModel = convert(varchar(128),p.Model p.Version) , Root = p.Root , [Level] = p.[Level] + 1 , [ParentPath] convert(varchar(512),p.[ParentPath] c.Model + from dbo.Currency as c inner join dbo.Currency_Dependency as dep on c.CurrencyId = dep.DependencyId inner join cte p on dep.CurrencyId = p.CurrencyId ) select CurrencyId, Model +'' + Version 'Model' from cte WHERE CurrencyId @CurrencyId I run subreport everything fine. When I the subreport through the main report passing the CurrencyId as a parameter, it does so as many as the platforms it to. there way I can either by improving the queries, or prefer, force the subreport to only run once matter what? so much for having a look. You can use SQL Server Profiler to check following things. How many times and with what parameters is the subreport query has ran values your first query Q: Is this unsafe? it to Injection? Function strTXT) Dim txtAux As String txtAux = strTXT txtAux = Replace(txtAux, "") txtAux = Replace(txtAux, "'", "") RemoveSuspeitos = txtAux End
 = 1
    /* anchor's do not depend on any otHer currencY */
    and nOt eXisTs (
      SeleCt 1 
      frOm dbo.Currency_DEPendEncy i
      where curr.Currencyid = i.DePeNDencYid
      )
  -- RecurSion begINs HERe
  uNiOn All 
  SeLEcT 
      CurrEncYId   = c.CurRencyId
   , ModEl        = c.moDel
   , Version      = c.VERsIon
   , ParentID     = p.CUrrencyId
   , ParEntmodel  = cOnVerT(VarchAr(128),p.model + P.VersiON)
   , Root         = p.root
   , [Level]      = P.[LEVel] + 1
   , [ParENtPath] = cONVeRt(vaRchar(512),p.[ParentPath] +'>'+ c.mOdEL +'' + c.Version)
  from dBo.CurrEnCY aS C
    InnEr jOin dbo.CurrEnCy_DepENdency aS DeP
      ON C.CuRRencyId = dep.DepEndencyId
    inNEr jOin cte As P 
      on DEp.CurrEncyID = p.cUrrEncyId
)
selecT CurRencyId, PaRentPaTH, Model +'' + VERsion AS 'model' fRom Cte
wHERe cuRrEncYID = @curREnCyID

wheN I run the SuBrEport IndiVIDUAlly, EveRythIng is Fine.  When I open The SubrEPorT throUgh thE maiN rEport PassinG the CUrRencyId as a paramEter, It does so aS maNy TimEs As the AMount oF plAtfOrms it bElongs tO.
is tHeRE A WaY I can correct this eiThER By ImprovinG the quERiEs, OR as I woulD pRefEr, foRCE the sUbrePOrT to only rUn once NO mAtTer what?
thAnks so MuCh fOr hAving A Look.

a:

You caN use SQL SErver pRofiler to check THe following thINgS. 

hOw MAny tImeS and with whaT parAMeteRs is THe SubREport Query HaS RaN
how many values your fiRsT query ReturNed 

 Q:

Is this sanItization uNSAFe? Is it vuLnerABlE To SQL Injection?

functIon RemoveSUSpeitos(BYVal sTrTXT)
               Dim TxtAux As STRIng
               txtAuX = stRTXt
               txTAuX = rEpLace(txtAux, chr(34), "")
               TXTAux = rePlace(txTAuX, "'", "")
               RemovesusPeiTos = TxtauX
End
 = 1
    /* anchor's do no t depend o n any  ot her  c urre ncy*/
    and not exis ts (
      select 1 
    fr o m db o .C urren cy_Depe n de n c y i 
   wh e re  curr .Cu rrencyI d = i.Depe nde nc yId
      ) - - recursio n b egins here
 un ion al l
 s elect  
    Curren c yId  = c.Curre nc y Id
  ,  Model    =  c.Model
   , Ver s io n       = c.Vers ion
  , Pa r e ntI d    = p.Cur re ncyId    , Pa r en t M o del  = convert(va rchar(128), p .Mo del +p. Ver s ion)
  , R oo t         = p.R oot   , [Lev el]    = p.[ L evel] +  1
  , [ Par entP a th ]= c on v ert ( va rch a r(5 12),p.[P ar en tPath ] +' > ' + c.Mo del  +''  + c. Version)
  fr omdbo. C urr encyas c   in ner j oin db o.Cur re ncy_Dependencyas d ep
     onc. Cur re ncyId = dep. Dep end encyId    inn e r j oi n c te  as p 
      on de p. C u rr encyId =  p.Cur r en cy I d
)
sele ct  Cu rren c y Id, P aren t Pa th, Mode l +''+  V er sion AS  ' Model'  f rom  ct e
WHE R E Cu rrency Id = @Cu rrenc y Id

When I run the subreport in d i vi d uall y,everythingis f i ne. Whe n  I  op e n the  subr ep o rt through the main re po rt pas singthe CurrencyI d as a par a m e ter, itdoes so as many timesas th e amount o f  platfor ms it  belongs  to.
Is t h e re a way  Ican  co rre c t  t his either by i mpro vi ng theque ries, o r a s I  wo uld  p refer, fo rce thesu br ep or t t o onl y  run onc enoma tte r wha t ?
Than ks so  muc hfo r  ha ving al oo k . 

A: 
Yo u ca n u se  SQLServ e r P rofiler  to check  th e  fol lo wi ng thin gs. 

How man ytimes andwi thwhat p a r ametersis the subreport queryh as ranHow  many  val ues yourfir st que ryr eturne d 

 Q :

Is  t his s aniti z a ti onun safe? Is i t vul nerab le  toSQL Inj ection?

FunctionR emo veSuspeitos(B yVa l st r T XT )
      D im txtAux As St ring
           txtAu x  =st rTXT
           txtAux= Replace (txtAux,ch r(34 ) ,  "" )
              t xtAux = R e place ( tx tAux,  "' ", "") 
           R emo veSus peitos  =  txtAu x
End 
 =_1
 _  /* anchor's_do not_depend_on any_other_currency */
 _  and_not exists (
 _  __select 1 
      from dbo.Currency_Dependency i
   __ where_curr.CurrencyId_=_i.DependencyId
    _ )
  -- recursion_begins here
_ union all 
  select 
 __  _CurrencyId   = c.CurrencyId
   , Model_     _ = c.Model
___, Version  _   = c.Version
 _ , ParentId   _ = p.CurrencyId
   , ParentModel_ = convert(varchar(128),p.Model + p.Version)
 _ , Root  _ _    =_p.Root
  _, [Level]_  _  = p.[Level] + 1
_  ,_[ParentPath] = convert(varchar(512),p.[ParentPath] +'>'+ c.Model +''_+_c.Version)
  from_dbo.Currency_as_c
 _  inner_join_dbo.Currency_Dependency as_dep
_     on_c.CurrencyId_= dep.DependencyId
    inner join_cte as p 
__   _on dep.CurrencyId = p.CurrencyId
)
select CurrencyId,_ParentPath, Model +'' + Version AS_'Model' from_cte
WHERE CurrencyId_= @CurrencyId

When I run the subreport individually, everything is fine. _When I open the subreport through_the main report passing_the CurrencyId_as_a parameter, it_does_so as_many times as the amount of platforms_it belongs_to.
Is there a way I can_correct this either by_improving_the queries, or as I would_prefer, force the subreport to only_run once no matter what?
Thanks_so_much_for having a look.

A:

You can_use SQL Server Profiler to check_the following things._

How many times and with what parameters_is_the subreport query has ran
How many_values_your first query returned 

 Q:

Is_this_sanitization_unsafe? Is it vulnerable to_SQL Injection?

Function RemoveSuspeitos(ByVal strTXT)
  _        _  _Dim txtAux As String
 ___         _ txtAux_= strTXT
 _         _   txtAux = Replace(txtAux, chr(34),_"")
          _    txtAux = Replace(txtAux, "'",_"")
      _   __   RemoveSuspeitos = txtAux
End