report design tips

Upload: abuihsan

Post on 05-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/15/2019 Report Design Tips

    1/32

    Report Design Tips and TricksSQL Server Technical Article

    Author: Fang Wang

    Thanks to Robert Bruckner and Chris Hays or their hel! "ith the content#

    Summary: This "hite !a!er covers best !ractices on re!ort design and hel!s you avoid

    co$$on $istakes "hen choosing a re!ort layout and out!ut or$at# Take advantage oe%isting !roduct eatures to achieve the results you "ant# The !a!er includes re!ort and

    code e%a$!les that i$!le$ent unctionality that is re&uently asked or# 

    'ublished: February ())*

    A!!lies To: +icrosot SQL Server ()), Re!orting Services

  • 8/15/2019 Report Design Tips

    2/32

    Filena$e: -(),.*(-/#doc (

    CopyrightThe inor$ation contained in this docu$ent re!resents the current vie" o +icrosot Cor!oration on the issues discussed

    as o the date o !ublication# Because +icrosot $ust res!ond to changing $arket conditions0 it should not be inter!reted

    to be a co$$it$ent on the !art o +icrosot0 and +icrosot cannot guarantee the accuracy o any inor$ation !resented

    ater the date o !ublication#

    This White 'a!er is or inor$ational !ur!oses only# +1CR2S2FT +A34S 52 WARRA5T14S0 46'R4SS0 1+'L147 2R

    STAT8T2R90 AS T2 TH4 15F2R+AT125 15 TH1S 72C8+45T#

    Co$!lying "ith all a!!licable co!yright la"s is the res!onsibility o the user# Without li$iting the rights under co!yright0

    no !art o this docu$ent $ay be re!roduced0 stored in or introduced into a retrieval syste$0 or trans$itted in any or$

    or by any $eans electronic0 $echanical0 !hotoco!ying0 recording0 or other"ise;0 or or any !ur!ose0 "ithout the e%!ress

    "ritten !er$ission o +icrosot Cor!oration#

    +icrosot $ay have !atents0 !atent a!!lications0 trade$arks0 co!yrights0 or other intellectual !ro!erty rights covering

    sub$ail addresses0 logos0 !eo!le0 !laces0

    and events de!icted in e%a$!les herein are ictitious# 5o association "ith any real co$!any0 organi=ation0 !roduct0

    do$ain na$e0 e>$ail address0 logo0 !erson0 !lace0 or event is intended or should be inerred#

     

    © ())* +icrosot Cor!oration# All rights reserved#

    +icrosot0 ?isual Basic0 and ?isual Studio are either registered trade$arks or trade$arks o +icrosot Cor!oration in the

    8nited States and@or other countries#

    All other trade$arks are !ro!erty o their res!ective o"ners#

  • 8/15/2019 Report Design Tips

    3/32

    /

    Table of ContentsIntroduction......................................................................................................2

    Best ractices and Tips.....................................................................................2

    7esign 9our Re!orts or 'eror$ance and Scalability############################################(

    Choose A!!ro!riate Rendering For$ats##############################################################.

    Control 'age Si=e############################################################################################.

    Check Re!orting Services Log Files####################################################################,

    8se 7evice1no to Control the Behavior o a Rendering 4%tension##########################*

    +ultivalue 'ara$eters######################################################################################*

    8sing R7L ro$ SQL Server Re!orting Services ()), in SQL Server Re!orting Services

    ()))##############################################################################################################

    Report Samples.................................................................................................!

    Custo$ Code or Aggregates############################################################################

    Scenario /: +edian;##################################################################################

    Scenario (: 7istinct Su$###########################################################################//

    1$age ?alue Reerring to a Te%tbo% ?alue#########################################################/(

    etting 7ata ro$ 7ierent Sources################################################################/-

    Changing the Re!ort Structure at Run Ti$e######################################################/,

    7yna$ic Field Based on 'ara$eter0 7yna$ic rou!ing##################################/,

    Changing the Filter 2!erator at Run Ti$e####################################################/

    7yna$ic Colu$ns#####################################################################################()

    7yna$ic Ro"s##########################################################################################((

    1nSco!e Function######################################################################################((

    7yna$ic 'age Breaks################################################################################(-

    Resetting the 'age 5u$ber on a rou!############################################################(,

    Hori=ontal Tables###########################################################################################(*

    reen Bar#####################################################################################################(

    Table####################################################################################################### (

    +atri%#####################################################################################################(

  • 8/15/2019 Report Design Tips

    4/32

    (

    1ntroduction+icrosotD SQL ServerE Re!orting Services is a co$!rehensive solution or creating0

    $anaging0 and delivering both traditional0 !a!er>oriented re!orts and interactive0 Web>

    based re!orts ro$ dierent ty!es o data sources# Re!orting Services !rovides a "ide

    variety o o!tions or re!ort controls that you can use to dis!lay data and gra!hicalele$ents in your re!orts# 9ou can create re!orts or your a!!lication by using one o the

    design tools shi!!ed "ith the !roduct0 including Re!ort 7esigner integrated "ith ?isual

    StudioD ()),0 and Re!ort Builder0 an ad hoc re!orting tool that enables business users to

    create their o"n re!orts and e%!lore cor!orate data0 based on a re!ort $odel# Re!orts can

    be rendered into a "ide range o or$ats such as HT+L0 6+L0 CS?0 4%cel0 '7F0 and i$age

    iles#

    Although Re!orting Services incor!orates co$$only used unctionality and $akes it easy

    and le%ible or users to create and $anage re!orts that $eet their s!eciic re&uire$ents0

    re!ort design can be a very challenging task given the co$!le%ity o business needs# Re!ort

    authors ace $any decisions and tradeos "hen choosing the best "ay to design and de!loy

    a re!ort# This "hite !a!er ans"ers the ollo"ing &uestions and !rovides a set o re!ort andcode sa$!les:

    • What are the best !ractices or designing a re!ort

    • Ho" do 1 avoid co$$on $istakes "hen choosing a re!ort layout and !icking an out!ut

    or$at

    • Ho" do 1 take advantage o e%isting eatures to achieve the results 1 "ant0 "hen no

    direct su!!ort is !resent

    "ote  This docu$ent assu$es that the reader is a$iliar "ith the Re!orting Services

    !roduct0 re!ort design conce!ts0 and !ossesses a basic kno"ledge on ho" a re!ort is

    !rocessed and $anaged by the re!ort server#

    Best 'ractices and Ti!sThis section describes so$e co$$on user scenarios and !rovides re!ort authors and

    ad$inistrators "ith useul inor$ation to hel! the decision>$aking and troubleshooting

    !rocesses#

    7esign 9our Re!orts or 'eror$ance andScalability

    For their re!orting !lator$0 $any organi=ations0 ro$ s$all>scale !ersonal businesses to

    large enter!rises0 use Re!orting Services as the $ain inor$ation delivery channel or daily

    o!erations# When handling large or co$!le% re!orts0 re!ort authors and ad$inistrators

    oten encounter &uestions such as:

    • Can $y re!ort handle a large a$ount o data

    • Ho" "ill the server be aected "hen $any users vie" a re!ort during !eak hours

    • Ho" do 1 troubleshoot a !eror$ance !roble$

  • 8/15/2019 Report Design Tips

    5/32

    -

    To achieve the best !eror$ance0 there are a nu$ber o actors you should take into

    account "hen designing your re!orts#

    #uery design

    A re!ort is !rocessed in the ollo"ing order: &uery e%ecution0 re!ort !rocessing0 and re!ort

    rendering# To reduce overall !rocessing ti$e0 one o the irst things you need to decide is

    "hich data to retrieve ro$ the data source and "hich calculations to include in the re!ort#Re!orting Services su!!orts a "ide range o data sources0 including !lain ile syste$s0

    advanced database servers0 and !o"erul data "arehousing syste$s# The unctionality o

    data sources and the structure o the re!ort deter$ine "hich o!erations should be done in

    the &uery0 as o!!osed to "hich o!erations should be done inside o the re!ort# Although the

    Re!orting Services !rocessing engine is ca!able o doing co$!le% calculations0 such as

    grou!ing0 sorting0 iltering0 data aggregation0 and e%!ression evaluations0 it is usually the

    database syste$ that is best o!ti$i=ed to !rocess so$e or all o these data o!erations# With

    that said0 al"ays kee! the ollo"ing in $ind#

    • $ptimi%e report &ueries.

    Query e%ecution is the irst ste! o the re!orting !rocess# Having a good understanding

    o the !eror$ance characteristics o your database syste$ is the irst ste! to good

    &uery design# For e%a$!le0 you can use SQL 'roiler to track the !eror$ance o your

    &ueries i you use SQL Server as the database server#

    • Retrie'e the minimum amount of data needed in your report.

    Add conditions to your &uery to eli$inate unnecessary data in the dataset results#

    1 the initial vie" o the re!ort sho"s only aggregated data0 consider using drill through

    to dis!lay details# 7rillthrough re!orts are not e%ecuted until the user clicks the

    drillthrough link0 "hereas sho"@hide re!orts or subre!orts are !rocessed during the

    initial re!ort !rocessing0 even i they are hidden#

    Rendering formats

    Re!orts can be e%!orted into various rendering or$ats through rendering e%tensions#

    7ierent rendering e%tensions !rovide dierent unctionality# Their !eror$ance and

    scalability characteristics are also very dierent# 9ou $ust understand the dierence in their

    behavior beore you can $ake the right choice to satisy your business re&uire$ents# For

    $ore inor$ation0 see Choose A!!ro!riate Rendering For$ats or 9our Business 5eeds in

    this !a!er#

    agination

    Re!orts are rendered into !ages based on "here !age breaks occur# Although the entire

    re!ort is !rocessed beore the rendering !hase0 the !eror$ance o the rendering e%tension

    is signiicantly i$!acted by the !age si=e# Also in so$e case or e%a$!le0 HT+L;0 ho" "ell

    the re!ort is dis!layed in the client tool de!ends on the !age si=e as "ell as other actors#For inor$ation on the dierent ty!es o !age breaks and ho" they are used in various

    rendering or$ats0 see Control 'age Si=e#

    Check the e(ecution log to assess performance

    2nce a re!ort is de!loyed on the re!ort server0 the ad$inistrator "ill "ant to $onitor the

    activities associated "ith the re!ort0 including ho" re&uently it is re&uested0 "hat out!ut

    or$ats are used0 ho" $any resources are consu$ed0 and other !eror$ance inor$ation#

  • 8/15/2019 Report Design Tips

    6/32

    .

    The Check Re!orting Services Log Files section describes ho" to use the e%ecution log to

    gather this data# 1t also tells you ho" to use the inor$ation to o!ti$i=e re!ort e%ecution#

    Choose A!!ro!riate Rendering For$atsRe!orting Services su!!orts seven rendering or$ats out o the bo%GHT+L0 6+L0 CS?0 710

    '7F0 1$age0 and +icrosot 4%cel# A rendering e%tension interace is also !rovided or third>!arty vendors to i$!le$ent additional rendering e%tensions to su!!ort other or$ats#

    The ollo"ing table contains a brie descri!tion o the built>in rendering e%tensions# They are

    listed in the order o $e$ory consu$!tion0 ro$ least to the $ost#

    HT+L@Webor$ control

    Renders into the or$at used or HT+L .#) bro"sers0

    including +icrosot 1nternet 4%!lorer0 5etsca!e

    5avigator *#/0 Fireo% Web Bro"ser# 2ne o the $ost

    !o!ular or$ats or online and interactive re!ort vie"ing0

    as "ell as the rendering e%tension used in the

    Re!ort?ie"er Web server control0 Re!ort +anager0 and

    or 8RL access#

    6+L

    Renders the re!ort data as an 6+L docu$ent# 1 an 6SLT

    transor$ation is s!eciied through device inor$ation

    settings0 the 6+L rendering e%tension could consu$e

    $ore $e$ory than the CS? rendering e%tension#

    CS?Renders re!ort data into co$$a>deli$ited !lain te%t

    iles# Also called the Te%t rendering e%tension#

    WinFor$ control@Re!ort

    'revie"

    The rendering e%tension used in the Re!ort?ie"er

    Windo"s For$s control dra"s directly to your screen# 1t

    is also used in the !revie" $ode or Re!ort 7esigner and

    Re!ort Builder# This is the other rendering or$at thatsu!!orts interactive re!ort vie"ing#

    '7FRenders into 'ortable 7ocu$ent For$at '7F; that can

    be o!ened and vie"ed "ith Adobe Acrobat .#) or later#

    1$age

    Renders a re!ort as a static i$age in bit$a!s or

    $etailes# Su!!orted i$age or$ats are #b$!0 #e$0

    #gi0 #

    the re!ort is handled by the Re!ort 'rocessing and Rendering engine# There are three ty!es

    o !age breaks: logical !age breaks0 sot !age breaks0 and !hysical !age breaks#

    )ogical page breaks

    Logical !age breaks are deined in the re!ort deinition by using the ageBreak*tStart 

    and ageBreak*t+nd !ro!erties in various re!ort ele$ents0 including grou!0 rectangle0

  • 8/15/2019 Report Design Tips

    7/32

    ,

    list0 table0 $atri%0 and chart# Logical !age breaks are considered in all rendering e%tensions

    e%ce!t or data rendering e%tensions 6+L and CS?;#

    Soft page breaks

    1nteractive rendering e%tensions HT+L and WinFor$ control; use the re!orts

    Interacti'e,eight and Interacti'e-idth !ro!erties to deter$ine !age si=e# The

    rendered !ages can be slightly larger than the s!eciied si=e0 thereore0 they are called soft pages# Sot !ages "ere introduced to solve the issue o getting long !ages in HT+L "hen

    re!ort authors did not include logical !age breaks in the re!ort deinition to achieve

    reasonable !age si=es# ?ery long !ages are not only unreadable0 but also cause

    !eror$ance !roble$s in 1nternet 4%!lorer# Sot !age breaks can be disabled by setting the

    Interacti'e,eight and Interacti'e-idth to =ero#

    hysical page breaks

    Set the age,eight and age-idth !ro!erties on the re!ort controls "here !hysical !age

    breaks occur# 'hysical !age breaks are used in !hysical !age rendering e%tensions0 such as

    '7F and 1$age# These rendering e%tensions res!ect the !age si=e !recisely during

    !agination# The age,eight and age-idth values deined in the re!ort deinition can be

    overridden by device inor$ation settings in the rendering e%tension# For details0 see 8se

    7evice 1no to Control the Behavior o a Rendering 4%tension#

    Check Re!orting Services Log FilesWhen you e%!erience !roble$s "ith re!ort e%ecution or need to inter!ret the !eror$ance

    characteristics o your re!orts0 check the log iles described in this section# Re!orting

    Services uses these log iles to record inor$ation about server o!erations and status#

    -indos *pplication log

    The re!ort server logs events to the Windo"s A!!lication log o the local co$!uter# 2nly

    inor$ation that can be useul or diagnosing a hard"are or sot"are !roble$ is logged# The

    event log is not intended to be used as a tracing tool# The Re!orting Services trace logs are

    used or that !ur!ose# 9ou can use the Windo"s 4vent ?ie"er to vie" and ilter the events

    based on the event sources0 ty!es0 and categories# For details on the event sources0 ty!es

    and categories0 see Windo"s A!!lication Log and Re!orting Services 4rrors and 4vents in

    SQL Server Books 2nline#

    Reporting Ser'ices trace logs

    Re!orting Services records detailed o!eration inor$ation in trace logs#

    • Trace log file names

    4ach o the Re!orting Services co$!onents creates a log ile "ith a uni&ue na$e# For

    e%a$!le0 the Re!ort Server Web Service trace logs are na$ed IRe!ortServerJKti$esta$!#logM0 and the trace logs or the Windo"s Service are

    na$ed IRe!ortServerServiceJKti$esta$!#logM#

    • Trace le'els

    The level o detail o the inor$ation that the server logs in trace iles can be conigured

    by setting DefaultTraceSitch in the coniguration iles# For the Re!ort Server Web

    service0 this o!tion is in the Web#conig ile# The s"itch or the Re!ort Server Windo"s

    service is in Re!ortingServicesService#conig# Four trace levels are available:

    http://msdn2.microsoft.com/en-us/library/ms157312.aspxhttp://msdn2.microsoft.com/en-us/library/ms165307.aspxhttp://msdn2.microsoft.com/en-us/library/ms157312.aspxhttp://msdn2.microsoft.com/en-us/library/ms165307.aspx

  • 8/15/2019 Report Design Tips

    8/32

    N

    / O error any e%ce!tion and restarts;

    ( O "arning or e%a$!le0 "arnings related to lo" resources;

    - O ino including inor$ational $essages;

    . O verbose

    By deault0 the trace level is set to -#

    • +rror information

    When a ailure ha!!ens in the re!ort server0 check the trace log or error details i there

    is not enough inor$ation given in the 81# The trace iles should contain the co$!lete

    stack trace du$!0 "hich is hel!ul to diagnose the !roble$# 2ne e%a$!le o this "ould

    be subre!ort errors# When a subre!ort ails0 it does not !revent the $ain re!ort and

    other subre!orts ro$ e%ecuting# A $essage is dis!layed in !lace o the subre!ort

    contents telling the user that an error occurred "hile e%ecuting the subre!ort# 9ou $ay

    "ant to vie" the trace log to ind out "hat the !roble$ "as#

    The trace logs are located in P+icrosot SQL ServerPKSQL Server 1nstancePRe!orting

    ServicesPLogFiles# 5e" log iles are created every ti$e a Re!orting Services co$!onent

    starts# They are created daily starting "ith the irst entry that occurs ater $idnight# The

    logs can beco$e very large0 de!ending on the traic on the Re!orting Services

    co$!onent# Thereore0 "hen looking u! ile contents0 search or the entries "ith the

    corres!onding ti$esta$!#

    Report Ser'er e(ecution log

    The e%ecution log is a database table that contains re!ort e%ecution inor$ation on a re!ort

    server# 1t is an internal table residing in the Re!ort Server catalog# The table na$e is

    4%ecutionLog# Server ad$inistrators can use the inor$ation in the e%ecution log to analy=e

    re!ort usage and e%ecution !eror$ance#

    The e%ecution log records data about "hich re!orts are e%ecuted0 "hen each re!ort starts

    and ends0 ho" $uch ti$e is s!ent on each !rocessing !hase0 "ho re&uested the re!ort0 and

    the e%!ort or$at# Follo"ing are ields you $ay ind !articularly interesting or !eror$ancetuning:

    TimeDataRetrie'al O Ti$e in $illiseconds; s!ent e%ecuting the &uery and retrieving data#

    Timerocessing O Ti$e s!ent !rocessing the re!ort#

    TimeRendering O Ti$e s!ent rendering the re!ort#

    /ormat O Re&uested rendering or$at#

    ByteCount O Si=e o rendered re!ort in bytes#

    RoCount O 5u$ber o ro"s returned ro$ &ueries#

    The co$bination o the ti$e s!ent in the three !rocessing !hases &uery e%ecution0 re!ort

    !rocessing0 and re!ort rendering; deter$ines ho" long re!ort e%ecution takes# Finding a

    good balance bet"een "hat to do in the &uery and "hat is !rocessed in the re!ort is very

    i$!ortant# These nu$bers can !rovide a great starting !oint or ad$inistrators and re!ort

    authors to $onitor and o!ti$i=e re!ort e%ecution on the server#

    To $ake it easier or users to vie" the e%ecution log data0 a sa$!le SQL Server 1ntegration

    Services SS1S; !ackage is shi!!ed as !art o the !roduct# This !ackage e%tracts the

  • 8/15/2019 Report Design Tips

    9/32

    *

    inor$ation ro$ the e%ecution log table and !uts it into a se!arate database# For details0

    see Querying and Re!orting on Re!ort 4%ecution Log 7ata in SQL Server Books 2nline#

    8se 7evice1no to Control the Behavior o aRendering 4%tension

    7evice inor$ation settings are a set o rendering !ara$eters that are !assed to a

    rendering e%tension# Through the use o device inor$ation0 users can override the deault

    settings s!eciied in the re!ort deinition and change the behavior o a rendering e%tension#

    There are dierent sets o device inor$ation settings or dierent rendering e%tensions# For

    a co$!lete list o settings0 see Re!orting Services 7evice 1nor$ation Settings in

    SQL Server Books 2nline# Follo"ing are so$e o the $ost co$$only used device

    inor$ation De'iceInfo; settings#

    ,T0)

    The )inkTarget device inor$ation setting s!eciies the value o the Target attribute used

    to render hy!erlinks in the re!ort# The deault behavior is to navigate "ithin the sa$e ra$e

    as the original re!ort# 9ou can target a s!eciic ra$e by setting it to the na$e o the ra$e#1t can also be set to Jblank o!ens u! a ne" "indo";0 Jsel in the current ra$e;0 J!arent

    in the i$$ediate ra$eset !arent; to Jto! the to! "indo" "ithout ra$e;#

    D/1Image

    1 an e%!licit age,eight or age-idth is s!eciied in the device inor$ation settings0 it

    overrides the value deined in the re!ort deinition# Thus0 dierent users can su!!ly dierent

    values "hen they e%!ort the sa$e re!ort to '7F or 1$age iles# Startage and +ndage 

    tell the rendering e%tensions to render a range o the !ages starting ro$ the Startage to

    the +ndage#

    +(cel

    1 you "ant the re!ort !age header rather than the irst ro" o the "orksheet to berendered as an 4%cel !age header0 set the Simpleage,eader device inor$ation setting

    to true# Since the unctionality su!!orted by an 4%cel !age header is &uite li$ited0 doing

    this $eans that you $ight lose inor$ation in your !age header#

    By deault0 the 4%cel rendering e%tension tries to !reserve 4%cel or$ulas "henever

    !ossible# ?isual BasicD #54T or$ulas are translated to 4%cel or$ulas# The reerences to

    re!ort ite$s on the current !age are converted to the a!!ro!riate cell reerences# 1 you

    dont "ant this behavior0 set $mit/ormulas to true#

    0)

    The value o the S)T !ara$eter s!eciies a relative 8RL o an 6SLT to a!!ly to the re!ort

    6+L# 5ote that only 6SL iles that are !ublished on the sa$e re!ort server can be used#By deault0 the 6+L rendering e%tension uses the original value o the e%!ression evaluation

    result "hen rendering a te%t bo%# The ty!e o the te%t bo% is set to the ty!e o the original

    value in the 6+L# 9ou can use the 3se/ormatted4alue device inor$ation setting to

    override this behavior# 1 it is set to true0 the or$atted value "hich is al"ays a string; is

    used instead# 1n this case0 the ty!e o the te%t bo% "ill be string#

    http://msdn2.microsoft.com/en-us/library/ms155836.aspxhttp://msdn2.microsoft.com/fr-fr/library/ms155397.aspxhttp://msdn2.microsoft.com/en-us/library/ms155836.aspxhttp://msdn2.microsoft.com/fr-fr/library/ms155397.aspx

  • 8/15/2019 Report Design Tips

    10/32

    +ultivalue 'ara$eters+ultivalue !ara$eters are very useul to $any users# This also see$s to be one o the areas

    that custo$ers need the $ost hel! "ith#

    A $ultivalue !ara$eter is a re!ort !ara$eter that can take a set o values# To deine a

    $ultivalue !ara$eter0 si$!ly add a !ara$eter and $ark it as $ultivalue "hen creating are!ort# There are t"o $ain scenarios "here $ultivalue !ara$eters are used#

    3se a multi'alue parameter inside a teport

    The !ro!erties e%!osed on a re!ort !ara$eter obbased

    arrays#

    =Parameters!.IsMultiValue > The !ara$eter deined as $ultivalue#

    =Parameters! .Count > Returns the nu$ber o values in the array#

    =Parameters! .Value(0) > Returns the irst selected value#

    =Parameters! .Label(0) > Returns the label or the irst selected value#

    =Join(Parameters! .Value) > Creates a s!ace se!arated list o values#

    =Join(Parameters! .Value, , ) > Creates a co$$a>se!arated list o

    values#

    ass the 4alue of a 0ulti'alue arameter to a Subreport

    7irectly !ass the value o a $ultivalue !ara$eter ro$ the $ain re!ort to the subre!ort:

    =Parameters!.Value

    Create a $ultidi$ensional obthe>ly S!lita0b0c0 0; and !ass it to a

    $ultivalue !ara$eter o the subre!ort#

    'ass the irst selected value ro$ the $ain re!orts !ara$eter:=Parameters!.Value(0)

    8sing R7L ro$ SQL Server Re!orting Services()), in SQL Server Re!orting Services ()))

    When you o!en a Re!ort 7einition Language R7L; ile that "as created in SQL

    Server ())) Re!orting Services in a SQL Server ()), version o Re!ort 7esigner0 or !ublish

    it to a SQL Server ()), re!ort server0 the ile is auto$atically u!graded to SQL Server ()),

    or$at# But is it !ossible to do"ngrade a R7L ile so that it can be used "ith the ()))

    version o the !roduct again There is no auto$ated tool to do this0 but you can $odiy the

    6+L ile $anually to acco$!lish it#

    To modify the RD) file

    /# Change the R7L na$es!ace:

    epla"e

    /it$

  • 8/15/2019 Report Design Tips

    11/32

    #mlns=$ttp%&&s"$emas.mi"roso't."om&slserer&reportin*&+00&-0&reporte'in

    ition ... >

    (# Re$ove the ollo"ing ele$ents entirely i !resent in the R7L ile:

    +2.3"m

  • 8/15/2019 Report Design Tips

    12/32

    /)

    /igure 5

    ,# Wra! the call to the unction in an aggregate and add it to an e%!ression in the detail

    ro"s# For e%a$!le:

     =Ma#(Coe.5Value(6iels!'iel.Name))

    Set the ,idden !ro!erty o the table colu$n or the te%tbo% to true so that it does not

    sho" u! in the re!ort#

    N# Fro$ a te%t bo% in the table ooter0 call into et+edian; to retrieve the value0 in this

    e%a$!le0 =Coe.4etMeian()as sho"n in Figure (#

    /igure 2

    Figure - sho"s "hat the inal re!ort looks like#

  • 8/15/2019 Report Design Tips

    13/32

    //

    /igure 6

    Scenario (: 7istinct Su$1 a dataset contains values or du!licate records0 you dont "ant to count those values

    $ulti!le ti$es# Re!orting Services su!!orts a CountDistinct unction0 but there is not a

    si$ilar unction or Sum# 9ou $ust do this by using custo$ code#

    To calculate Distinct Sum by using custom code

    /# 2!en the Report roperties dialog bo% and click the Code tab# 7eine a hash table and

    a unction that takes an argu$ent# 1nside the unction0 check the value o the argu$ent

    against the hash table# 1 the value does not e%ist yet0 add it to the total and save it in

    the hash table#

  • 8/15/2019 Report Design Tips

    14/32

    /(

    /igure 7

    (# Wra! the call to the unction in an aggregate and add it to an e%!ression in the sco!e

    "here you "ant to calculate the su$0 or e%a$!le:

    =7um(Coe.Cal"ulate7um(6iels!8rerI9.Value, 6iels!6rei*$t.Value))

    -# 1n the te%t bo% "here you "ant to dis!lay the su$0 retrieve the calculated aggregatevalue:

    =Coe.Cal"ulate7um(Not$in*, 6iels!6rei*$t.Value)

    1$age ?alue Reerring to a Te%tbo% ?alue7irect reerences to ield values in !age headers and ooters are not currently !ossible# A

    co$$on "orkaround is to add a hidden te%tbo% in the re!ort body0 and reer to the te%tbo%

    value ro$ the !age header or ooter# 7oes this "ork or an i$age 9es0 but since the i$age

    data is a binary array0 "hile the te%tbo% value is a string0 you need to use a +icrosot #54T

    baseN. encoding $echanis$ to convert the data bet"een binary and string ty!es#

    To add an image that uses the 'alue of a te(tbo(/# 1n the Re!ort 7esigner0 add a te%tbo% in the re!ort body# 8se the ToBase87String 

    unction to encode the binary data to string in the value e%!ression o the te%tbo%0 or

    e%a$!le:

    =Conert.:o;ase7trin*(6iels!Lar*eP$oto.Value)

    /igure 9

    (# 1n the !age header0 add an i$age# Set the source ty!e to database0 and the value to:

    =Conert.6rom;ase7trin*(eportItems!Lar*ePi"ture.Value)

  • 8/15/2019 Report Design Tips

    15/32

    /-

    This uses /romBase87String to decode the te%tbo% value back into binary#

    /igure 8

    etting 7ata ro$ 7ierent SourcesRe!orting Services doesnt currently su!!ort using $ulti!le datasets in one data region# To

    dis!lay an aggregate value ro$ the dataset0 s!eciy the dataset sco!e in the aggregate

    unction0 or e%a$!le0 =7um(6iels!6rei*$t.Value, 9ata7et+?)# This synta% "orks even

    in a data region that is bound to a dierent dataset# 1 ho"ever0 you need to correlate the

    data ro$ the t"o datasets in one data region0 use the ollo"ing t"o "orkarounds:

    • +odiy the &uery to return data ro$ both datasets as one dataset# 1 the &ueries are

    based on dierent databases0 use SQL 2'45R2WS4T#

    • 8se subre!orts# Try adding a subre!ort that receives a !ara$eter ro$ the $ain re!ort

    and gets data ro$ another data source based on the !ara$eter value#

    To use the subreport approach

    /# Add a table to the $ain re!ort# Bind it to 7ataSet/# 1n the detail ro"0 dis!lay the values

    you "ant ro$ 7ataSet/# Add a subre!ort and in the Subreport roperties dialog bo%0

    !ass the ield ro$ 7ataSet/ as a !ara$eter#

  • 8/15/2019 Report Design Tips

    16/32

    /.

    /igure

    (# Create a subre!ort that receives a !ara$eter ro$ the $ain re!ort# Reerence the

    !ara$eter value in the &uery to retrieve the records or the corres!onding !ara$eter

    value and dis!lay the data ro"s#

    /igure ;

    The ollo"ing igure sho"s the rendered $ain re!ort#

  • 8/15/2019 Report Design Tips

    17/32

    /,

    /igure !

    Changing the Re!ort Structure at Run Ti$eA re&uently asked &uestion is "hether it is !ossible to change the re!ort structure at run

    ti$e# 9ou can0 o course0 dyna$ically generate R7L iles in your custo$ a!!lication# There

    are also other "ays to $odiy the structural ele$ents in the re!ort deinition to achieve this#

    This section describes various scenarios and solutions#

    7yna$ic Field Based on 'ara$eter0 7yna$icrou!ing

    Ho" do 1 decide "hich ield value to use dyna$ically0 or e%a$!le0 based on a !ara$eter in

    $y re!ort Ho" can 1 give $y users the ability to dyna$ically select the ields on "hich to

    grou! "ithin a re!ort

    8se this synta% to reer to a ield value in your e%!ression: =6iels(Parameters!

    .Value).Value#To change the field reference and group e(pressions based on user input

    /# 1n Re!ort 7esigner0 o!en the Report arameters dialog bo%# Add a re!ort !ara$eter

    that re!resents the ield you "ant to grou! the re!ort data on#

  • 8/15/2019 Report Design Tips

    18/32

    /N

    /igure 5<

    (# 1n the Details =rouping dialog bo% or the table0 set the grou! e%!ression to

    =6iels(Parameters!4roup8rers;@.Value).Value

  • 8/15/2019 Report Design Tips

    19/32

    /*

    /igure 55

    -# Change the te%t bo% e%!ression in the re!ort to dis!lay the corres!onding ield value

    based on the !ara$eter value by using the 11F unction0 or e%a$!le:

    =II6(Parameters!4roup8rers;@.Value=CustomerI9, [email protected],

    6iels!6irstName.Value A  A 6iels!LastName.Value)

    The ollo"ing igure sho"s the re!ort "hen =roup$rdersBy is Custo$er# 

    /igure 52

    Here is ho" the re!ort looks "hen =roup$rdersBy is changed to 4$!loyee:

  • 8/15/2019 Report Design Tips

    20/32

    /

    /igure 56

    Changing the Filter 2!erator at Run Ti$e1t is not !ossible to change the ilter o!erator at run ti$e# But you can include all the

    conditions in the ilter e%!ression and leave the ilter o!erator and the value as static iltero!erator is IM0 and ilter value is ItrueM;# This "ay0 by dyna$ically s"itching the

    conditions in the ilter e%!ression by using 11F0 you can achieve the eect o changing the

    ilters based on user in!ut#

    To dynamically change the filter conditions based on parameter 'alue

    /# 1n Re!ort 7esigner0 o!en the Report arameters dialog bo%# Add a re!ort !ara$eter

    or the ilter o!erator# 1 you "ant the user to be able to control the nu$ber to co$!are

    against0 add a second !ara$eter#

    /igure 57

  • 8/15/2019 Report Design Tips

    21/32

    /

    (# 2!en the Table roperties dialog bo% and click the /ilters tab# Set u! the ilter on the

    table or the dataset or grou!;# The ilter e%!ression in this e%a$!le is:

    =II6(Parameters!6ilter8p.Value=>=, 6iels!BnitsIn7to".Value >=

    Parameters!Bnits.Value, 6iels!BnitsIn7to".Value

    < Parameters!Bnits.Value)

    /igure 59

    Figure /N sho"s ho" the re!ort looks "hen the value o Filter2! is set toreatThan2r4&ual#

  • 8/15/2019 Report Design Tips

    22/32

    ()

    /igure 58

    And "hen the user changes the !ara$eter value to LessThan:

    /igure 5

    7yna$ic Colu$ns1d like to !rogra$$atically deter$ine the colu$ns to dis!lay based on "hat is returned by

    the dataset# 1s that !ossible

    9es0 you can deine a table "ith all the !ossible colu$ns0 then decide "hether to sho" each

    colu$n based on the value o the Is0issing !ro!erty on Field# Here is an e%a$!le that

    sho"s inor$ation ro$ t"o dierent database tables based on user selection#

    To add dynamic columns to your report

    /# 1n Re!ort 7esigner0 o!en the Report arameters dialog bo%# Add a re!ort !ara$eter

    or users to select "hich table to dis!lay#

  • 8/15/2019 Report Design Tips

    23/32

    (/

    /igure 5;

    (# 7eine a colu$n or every ield you "ant to dis!lay ro$ the t"o tables# For the ,idden 

    !ro!erty o the colu$n0 set the e%!ression to the ollo"ing:

    =II6([email protected]*, true, 'alse)

    This is sho"n in Figure /

  • 8/15/2019 Report Design Tips

    24/32

    ((

    /igure 5!

    7yna$ic Ro"s+y dataset contains a large a$ount o data# Can 1 control ho" $any ro"s are sho"n

    initially through a !ara$eter0 and toggle the rest

    9es0 set the ,idden !ro!erty on the ro"s to:

    = oDNumber(9ata7et-) > Parameters!oDCount.Value

    Set the ToggleItem to a te%tbo% that you "ant to toggle the rest o ro"s "ith0 as sho"n in

    the ollo"ing igure#

    /igure 2<

    1nSco!e Function+y $atri% sho"s the !ercentage o the sales to a custo$er out o the total sales or each

    e$!loyee# 1n the subtotal cells0 this is al"ays going to be /))U0 "hich is not useul# Ho"

    can 1 get dierent contents in the subtotal cells

    8se the InScope unction in your e%!ression to do this# For e%a$!le0 su!!ose you have a

    ro" grou!ing called I$atri%/JCusto$er17M;0 and a colu$n grou!ing called

     I$atri%/J4$!loyee17M;# To sho" dierent contents in the colu$n subtotal cells0 set the cell

    te%tbo% e%!ression to:

    =II6(In7"ope(matri#-ECustomerI9),

    CountoDs()&CountoDs(matri#-EFmplo@eeI9), CountoDs())

  • 8/15/2019 Report Design Tips

    25/32

    (-

    7yna$ic 'age BreaksFor the logical !age breaks deined in the R7L0 the only o!tions see$ to be turning the$ on

    or o# There is no e%!ression or the$# 1s it !ossible to dyna$ically change "hich grou!s

    have !age breaks either beore or ater

    1t is !ossible0 although not very straightor"ard# 9ou create a du$$y grou! "ith !agebreak at end e&ual to true# The e%!ression or the grou! "ill be set according to a

    !ara$eter value#

    To add dynamic page breaks based on the parameter 'alue

    /# 2!en the Report arameters dialog bo%# 7eine a re!ort !ara$eter or the user to

    control the !age break#

    /igure 25

    (# Add a du$$y grou! in your re!ort# Turn o the grou! header@ooter0 and enable age

    break at end# Set the grou! e%!ression to:

    =II6(Parameters!Pa*e;rea.Value, 6iels!Cate*[email protected], -)

  • 8/15/2019 Report Design Tips

    26/32

    (.

    /igure 22

    The ollo"ing igure sho"s the re!ort "hen the !age break is turned on#

    /igure 26

    And "hen it is turned o:

  • 8/15/2019 Report Design Tips

    27/32

    (,

    /igure 27

    Resetting the 'age 5u$ber on a rou!

    1 have $any !ages and $any grou!s in $y re!ort# 1 can use =lobals>age"umber todis!lay the current !age nu$ber in the !age header# But 1 "ant to reset the !age nu$ber

    back to one every ti$e 1 enter a ne" grou!# Ho" do 1 do this

    Resetting the !age nu$ber on grou! breaks is not natively su!!orted0 but it can be

    achieved by tracking grou! breaks in a shared variable in custo$ code and subtracting o

    the !age oset o the irst !age o the grou! ro$ the current !age nu$ber#

    To reset the page number at the start of each group

    /# +ake sure that in the re!ort there is a te%t bo% that contains the grou! e%!ression# 1n

    this e%a$!le0 this is the Category te%t bo%#

  • 8/15/2019 Report Design Tips

    28/32

    (N

    /igure 29

    (# 2!en the Report roperties dialog bo% and click the Code tab# Add shared variables to

    track the current grou! and !age oset# Add a custo$ unction to set the shared

    variables and retrieve the grou! !age nu$ber as sho"n in the ollo"ing igure#

    /igure 28

    -# 8se the unction in the !age header:

    =Coe.4et4roupPa*eNumber(eportItems!Cate*[email protected],4lobals!Pa*eNumber)

    The ollo"ing igure sho"s one o the !ages in the rendered re!ort "here the grou!

    !age nu$ber is reset "hen starting a ne" grou!#

  • 8/15/2019 Report Design Tips

    29/32

    (*

    /igure 2

    "ote  Because this solution uses static variables0 i t"o !eo!le run the re!ort at thee%act sa$e $o$ent0 there is a sli$ chance that one "ill break the others variable state#

    Hori=ontal Tables1s it !ossible to rotate a table in Re!orting Services 8sually a table gro"s vertically0 based

    on the nu$ber o detail ro"s# What i 1 "ant it to gro" hori=ontally

    Try using a $atri% instead o table# The table header beco$es a static $atri% ro" header#

    The re!ort detail "ould be the colu$n grou!ings youll need to grou! on a ield thats

    uni&ue across dierent ro"s i you "ant each data ro" to sho" u! as a colu$n;# 'ut the

    ooter in the subtotal colu$n you $ay need to use the InScope?@ unction to dis!lay

    contents dierent ro$ the detail inor$ation;#The ollo"ing igure sho"s a vertical table and a hori=ontal table that dis!lay the sa$e set

    o data#

    /igure 2;

  • 8/15/2019 Report Design Tips

    30/32

    (

    reen BarCan 1 create a table or $atri% in "hich every other ro" is shaded

    Table8se =II6(oDNumber(Not$in*) Mo +, 5li"e;lue, /$ite) to control the backgroundcolor !ro!erty conditionally#

    /igure 2!

    +atri%1t is $ore diicult to create a $atri% "ith every other ro" shaded because every ro" in the

    $atri% $ust be a grou!# There is currently no rou!5u$ber; unction on "hich to base a

    green>bar calculation# Ho"ever0 rou!5u$ber can be $ostly; si$ulated by using the

    Running4alue unction to return a running distinct count o grou! e%!ression values#

    =II6(unnin*Value([email protected],Count9istin"t,Not$in*) Mo +,

    5li"e;lue, /$ite)

    To create a matri( ith the greenAbar effect

    /# Add a rectangle to the ro" grou! header# 1n the rectangle0 dro! the te%t bo% or the ield

    you "ant to dis!lay in the header# Add another te%t bo% na$ed Color; to calculate the

    na$e o the color based on the ollo"ing e%!ression:

     =II6(unnin*Value([email protected], Count9istin"t, Not$in*) Mo +,

    5li"e;lue?, /$ite?)

    Set the te%t bo%s ,idden !ro!erty to true#

  • 8/15/2019 Report Design Tips

    31/32

    (

    /igure 6<

    (# Set the background color o the rectangle and the $atri% cell to =eportItems!

    Color.Value#

    /igure 65

    The ollo"ing igure sho"s the rendered $atri%#

  • 8/15/2019 Report Design Tips

    32/32

    -)

    /igure 62

    /or 0ore Information• SQL Server Re!orting Services:

    htt!:@@"""#$icrosot#co$@s&l@technologies@re!orting@deault#$s!%

    • +S75 Re!orting Services: htt!:@@$sdn#$icrosot#co$@s&l@bi@re!orting@deault#as!%

    • Tech5et Re!orting Services:htt!:@@"""#$icrosot#co$@technet@!rodtechnol@s&l@()),@technologies@r!tsvcs#$s!%

    • Books 2nline Re!orting Services:

    htt!:@@$sdn(#$icrosot#co$@en>us@library@$s/,/)NSQL#);#as!%

    7id this !a!er hel! you 'lease give us your eedback# 2n a scale o / !oor; to ,

    e%cellent;0 ho" "ould you rate this !a!er

    http://www.microsoft.com/sql/technologies/reporting/default.mspxhttp://msdn.microsoft.com/sql/bi/reporting/default.aspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/technologies/rptsvcs.mspxhttp://msdn2.microsoft.com/en-us/library/ms159106(SQL.90).aspxmailto:[email protected]?subject=White%20paper%20feedback:%20Report%20Design%20Tips%20and%20Trickshttp://www.microsoft.com/sql/technologies/reporting/default.mspxhttp://msdn.microsoft.com/sql/bi/reporting/default.aspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/technologies/rptsvcs.mspxhttp://msdn2.microsoft.com/en-us/library/ms159106(SQL.90).aspxmailto:[email protected]?subject=White%20paper%20feedback:%20Report%20Design%20Tips%20and%20Tricks