SQL Server Performance


Discussion in 'Performance Tuning for DBAs' started by Leo, Feb 1, 2004.

  1. Leo New Member

    Calling expert help!!!
    I have a table called table1. The table1 consist of 3 column.

    How to avoid displaying the repeating Itemcode value, but description and location still displaying?
    The output look like this.

    ItemCode Description Location
    0001 Shipping USA
    Process JAPAN
    0002 Process11 Ohio
    0003 Shipping Sin

    The record row 2 for ItemCode value repeating so displaying 0001 on first row and space for second row, but the description and location still displaying....
    Any idea?


  2. bambola New Member

    This seems to be like something that should be done on client side.
  3. Chappy New Member

    I agree with bambola, this sort of logic is well suited to client language since you have to loop through the result set anyway.<br />However, since im in the mood for sql problems, heres an example <img src='/community/emoticons/emotion-5.gif' alt=';-)' /><br />Note that it takes some assumptions on how you order the results within an item code<br /><br /><pre><br />select <br />"ItemCode_Label"= CASE <br />WHEN A.Description = (select TOP 1 B.Description from Table1 B where A.ItemCode = B.ItemCode order by B.Description ASC) <br />THEN CONVERT(varchar(50), A.ItemCode)<br />ELSE ''<br />END,<br />A.Description, A.Location<br />from <br />Table1 A <br />order by<br />A.ItemCode, A.Description<br /></pre><br /><br />I might have broken the logic somehow by renaming the fields from my schema to yours. Basically the way it works is to say, if the current row is the first row in that itemcode, when ordered by description, then output itemcode, otherwise its not the first row in that itemcode, so output a blank.<br />Requires that rows within the itemcode are output in order of description.<br />
  4. Chappy New Member

    Also, this question is not related to performance tuning. It should instead appear in 'general developer questions'.<br />Certainly the query I posted is in no way the best performing method for this task <img src='/community/emoticons/emotion-5.gif' alt=';-)' />

Share This Page