• is250sp (3/6/2013)


    In my dataset I have this script. Report parameter @acct is set as multi-value. When I select a single value it runs fine, however when I select multi-value I get the error....Incorrect syntax near '+'

    EXECUTE ('USE ' + @dbname + '

    select g.cpnyid,g.JrnlType,g.Module,g.PerPost,g.Acct,g.Sub,substring(g.sub,6,5) as Cost_Ctr,left(g.sub,3) as Dept,substring(g.sub,4,2) as Legal_Entity

    ,g.DrAmt,g.CrAmt,0 as Amt,g.TranType,g.BatNbr,g.ID,g.refnbr as VONbr_InvNbr,g.ExtRefNbr as Vendor_InvNbr,g.TranDesc

    from gltran g

    where left(g.perpost,4) = ' + @year + '

    and right(g.perpost,2) = ' + @month + '

    and left(g.acct,1) in (' + @acct + ')

    and (g.dramt <> 0 or g.cramt <> 0)')

    You probably need to modify your dynamic sql. Without seeing how you are actually building the sql (meaning we need to know how data is being passed in the the variables) it is hard to know what suggestions to make. Looking at part of the code, I can already tell it needs work to make some of the WHERE clause SARGable.