How to add blank rows between groups of duplicate rows?

here is my setup
create table #tmpA(rowID int identity(1,1), fName varchar(10), lName varchar(10))
insert into #tmpA
select 'a', 'b' union all
select 'a', 'b' union all
select 'c', 'd' union all
select 'c', 'd' union all
select 'e', 'f' union all
select 'e', 'f' union all
select 'g', 'h' union all
select 'g', 'h'
select distinct fName, lName
into #tmpB
From #tmpA
select t1.* from #tmpA t1 Join #tmpB t2 on t1.fName = t2.fName and t1.lName = t2.lName
--output
rowID  fName  lName
1             a         b
2             a         b
3             c         d
4             c         d
5             e         f
6             e         f
7             g         h
8             g         h
I want to add blank rows between rows 2 & 3 and between rows 4 & 5 and between rows 6 & 7 in the join query above.  Is there Tsql that can accomplish something like this to make the join query result look like the following output?
rowID  fName  lName
1            a          b
2            a          b
3            c          d
4            c          d
5            e          f
6            e          f
7            g          h
8            g          h
or if this is not possible I could go with an output like this:
rowID  fName  lName
1             a         b
2             a         b
3
4             c         d
5             c         d
6
7             e         f
8             e         f
9
10           g         h
11           g         h
Rich P

I came up with the following on my own.  I was just hoping there might be a fancier way to do this - like without looping -- and yes, I could/should do this in a presentation layer, but I just wanted to do this in Query Analyzer (or whatever they call
it now -- SSMS ...) -- BTW, thanks CELKO for the suggestion about how to insert multiple rows using Values -- works great.
If (object_id('tempdb..#tmpA') is not null) drop table #tmpA
If (object_id('tempdb..#tmpC') is not null) drop table #tmpC
create table #tmpA(rowID int identity(1,1), fName varchar(10), lName varchar(10))
insert into #tmpA
values
('a','b'),
('a','b'),
('c','d'),
('c','d'),
('e','f'),
('e','f'),
('g','h'),
('g','h')
create table #tmpC(rrowID int Identity(1,1), rowID int, fName varchar(10), lName varchar(10))
declare @i int, @s varchar(10), @t varchar(10), @u varchar(10), @v varchar(10)
select @i = min(rowID) from #tmpA
set @u = 'xx'
While (@u != 'yy')
Begin
   select @s = fName, @t = lName from #tmpA Where rowID = @i
   if exists(select 1 from #tmpA Where rowID = @i + 1)
      select @u = fname, @v = lName From #tmpA Where rowID = @i + 1
   else
      set @u = 'yy'
    if @s = @u And @t = @v
       begin  
         Insert Into #tmpC(rowID, fName, lName) Select * from #tmpA Where rowID = @i
         Insert Into #tmpC(rowID, fName, lName) Select * from #tmpA Where rowID = @i + 1
       end      
    else
       begin
          Insert Into #tmpC(rowID, fName, lName) Select null, '', ''  
       end
    set @i = @i + 1
End
select * from #tmpC
--output from #tmpC
rrowID  rowID  fName  lName
  1            1         a        b
  2            2         a        b
  3          NULL 
  4            3         c        d
  5            4         c        d
  6          NULL  
  7             5         e        f
  8             6         e        f
  9           NULL  
  10           7          g        h
  11           8          g        h
  12         NULL  
Rich P

Similar Messages

  • How to add blank page to existing Document In Adobe Dc

    how to add blank page to existing Document In Adobe Dc Pro

    Hi thashrifs16749461,
    You can add a blank page using Adobe Acrobat DC by following the below instructions :-
    1) Open your existing pdf document in Acrobat DC.
    2) Choose the 'Organize Page' option form the Tools pane on the right as shown below in the screen shoot.
    3) Now at the top you will see all the tools to Organize the page, Click on 'Insert' & select 'Blank Page' from the drop-down to insert blank pages.
    *Shortcut : If you are using windows computer you can use ' Shift+Ctrl+T ' key to insert blank pages.
    In case if you experience any issue or have any query please let us know. We will be happy to help you.
    Regards,
    Aadesh

  • How to add the Profit center Group in the PA report KE33.

    Hi Frnds,
    How to add the Profit center Group in the PA report KE33.Iam not able to find PC group in the list to add to the Charateristics already added.

    Hi
    PC group is not available as a Char in COPA..
    if you want to do that, either create a Char Hierarchy in KES3 for the Char Profit Center
    OR
    Create a WW char in KEa5 and write a derivation rule using the method "Enhancement" .. Write ABAP Code in COPA0001 exit
    bt, Ajay M

  • In Share point 2013 how to add more than 2 group by in list

    In Share point 2013 how to add more than 2  group by in list .

    Hi,
    According to your post, my understanding is that you wanted to group by on more than 2 columns in a List View in SharePoint 2013.
    There is no out of the box way to achieve your scenario directly.
    As a workaround, we can use the following method to achieve it.
    First, we can insert Data View Web Parts in SharePoint Designer 2013.
    It’s because the SharePoint Designer 2013 can’t support Design view, then the Data View Web Parts XSL cannot be visually manipulated.
    You can refer to the following article to insert a Data View Web Part.
    http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=259
    And then, you can use the following solution that can be used to
    group by on more than 2 columns in a view
    to implement it in SharePoint Designer 2013.
    http://techtrainingnotes.blogspot.com/2011/01/sharepoint-group-by-on-more-than-2.html
    http://chanakyajayabalan.wordpress.com/2010/03/15/group-by-for-more-than-two-columns-in-sharepoint-list/
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to add a new excel sheet  when the row count exceed more than 65 k

    am working on business intellignence am able to export the data to excel sheet but my data exceeds the sheet limit so how to add to another sheet when the last row is hit ..???
    any suggestions warm welcome...
    help me to fix this issue...

    You've not specified how you're generating the Excel file. Are you using POI? JExcel? What?
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How to add blank line below the table/row whenever there is no data

    Hello Everyone,
    I have a table in my report template like below:-
    Children / Dependents: Name / Comments: Grandchildren: Name / Comments:
    Son John Daughter Smith
    Daughter Laura Son Kevin
    Son Bill None NA
    When i run the report I need to achieve the following conditions:-
    Condition 1: Loop through all rows and whenever there is data in any row in the table...I need to Populate and print it.
    Condition 2: When Loop is ended, when you see there is no data in any row in the table... add a dash line at the end of the table.
    Condition 3: Total no of populated rows + blank dash line <= Max no of rows in DB. And when max no of populated rows in report = max no of rows in DB/UI ... don’t print dash line.
    I want to achieve these conditions. Can you please help me.
    Thanks..Rithesh

    Hello Everyone,
    I have a table in my report template like below:-
    Children / Dependents: Name / Comments: Grandchildren: Name / Comments:
    Son John Daughter Smith
    Daughter Laura Son Kevin
    Son Bill None NA
    When i run the report I need to achieve the following conditions:-
    Condition 1: Loop through all rows and whenever there is data in any row in the table...I need to Populate and print it.
    Condition 2: When Loop is ended, when you see there is no data in any row in the table... add a dash line at the end of the table.
    Condition 3: Total no of populated rows + blank dash line <= Max no of rows in DB. And when max no of populated rows in report = max no of rows in DB/UI ... don’t print dash line.
    I want to achieve these conditions. Can you please help me.
    Thanks..Rithesh

  • How to add blank lines (in column) in SQLplus

    I get error when doing below insert, how do I add blank lines in column (via SQLplus)?
    insert into a values(1, '78 ABC house,
    Some Road
    London E34');
    Thanks

    Just set "SQLBLANKLINES" to ON:
    SQL> set sqlblanklines on
    SQL>
    SQL> insert into dept values (50, 'This department
      2
      3  has several
      4
      5  blank lines','This
      6
      7  Loc') ;
    1 row created.
    SQL> select * from dept where deptno = 50 ;
        DEPTNO DNAME                          LOC
            50 This department                This
               has several                    Loc
               blank lines
    1 row selected.
    SQL>

  • How to add a default user group for multiple document type's?

    Hi,
    I am trying to add same default user group for different document types when MA is created. Is there any way to setup using a single "Document Security Template"? Or I need to create different templates for different document types?
    Please confirm.
    Thanks,
    Saloni

    Hi Saloni,
    Based on what your specific requirement, it might be easier to do it with scripting.
    If you are doing it using Document Security Templates, you would have to create a Document Security Template for each of the 6 MA types and assign the default group. Create another one and leave the Document Type field blank, so it will apply to the other 4 MA types that don't have a default group.
    Regards,
    Vikram

  • HOW TO ADD / EDIT AN ITEM GROUP

    I am in the Item Master Data window and am entering a new Item Number.  I want to associate it with a new Item Group from the pull down menu but it will not allow me to add to this list.  How can I add a new Item Group?  Also, how can I edit a current Item Group title to change it to another name?

    Hi
    To solve your issues ,
    Go to system administration >setup>Inventory-->Item group .
    If you need to Add --Press Ctrl A
    If you want to edit -- find the item group -- and edit it .
    This should solve your problem
    Thank you
    Bishal

  • How to add disk to disk group File System in oracle windows

    Hi all
    Please any body can help ... I need to know how can I add disk to disk group
    I have Oralce 11g Database RAC Setup with 2 nodes node1 and node2 , ASM not enabled , Windows OS 2003 , I have shared storage (G, H and O ) My system administrator add additional SAN Storage (R) to my setup, how can I add the new disk to disk group.
    Please help

    I have Oralce 11g Database RAC Setup with 2 nodes node1 and node2 , ASM not enabled , Windows OS 2003 , I have shared storage (G, H and O ) My system administrator add additional SAN Storage (R) to my setup, how can I add the new disk to disk group.If ASM is not enabled that mean, Database is running on normal file system?
    Hi thanks for you help.,,, But my system admnistrator already did thies steps,... I think my question was not clear enough
    I mean after I add the disk group from O.S side what shall I do from Oracle Side? Since From windows explorer I can see the new drive.If the volumes are ready, you can use ASMCA to configure diskgroups.

  • How to add members in REDO group in RAC

    Hi All
    I need to know the syntax to add members in redolog group in RAC database. Currently i have 4 groups (2 belonging to each thread) and one member in each group. I want to multiplex.
    Thanks in advance

    Check out:
    http://www.lc.leidenuniv.nl/awcourse/oracle/rac.920/a96600/mancrea.htm

  • How to add a line between the two text fields  in JTabbed Pane

    Hi Friends,
    I would like to add a Line between some text fields to seperate them.. I added those text Fields to a tabbed Pane.. Please help me to create a line between the TextFields......

    http://java.sun.com/docs/books/tutorial/uiswing/components/separator.html

  • How to add some text between columns in dashboard prompt?

    Hi,
    OBIEE version:10.1.3.4.1
    Can we add some words between columns in dashboard prompt?
    like, I want to add OR, make sure user not to select different month, if selected the different months it will make the report no data.
    Month OR Date Range(this is a calendar)
    Does anyone have any idea about this?
    Thanks in advance!
    Regards,
    Anne

    Hi,
    If you are using the prompts with presentation variables or referring only the columns separately then you can create individual prompts and place static text between them.
    But if you need to have both the prompt columns together then create the prompts and use 'space' as the label names for both.(ie prompts would appear but the name wont appear). And create a static text in the page or in a report and place in the page. Which appears as the name of the prompt with 'OR' between the prompt names.
    This should solve your problem.
    Edited by: MuRam on Jan 13, 2012 10:18 AM

  • How to write the query to find the duplicate rows?

    Hi,
    How will I find the duplicate rows in the table?
    I have a table called ITEM
    Select item_no,mfg_id from item
    Item Mfg_ID
    178 06278
    178 06589
    238 5489
    289 7895
    289 7596
    Now I want to find only the duplicate rows i.e.,178 & 289 is coming twice.
    How will get the all duplicate rows in the table?

    nihar2 wrote:
    Convert to
    SELECT it.item,
         im.mfg_item,
         im.manufacturer,
         im.description
    FROM (SELECT it.item,
         im.mfg_item,
         im.manufacturer,
         im.description,
         count(it.item) over(partition by it.item order by it.item) cnt
         FROM item it,item_mfg im
         WHERE it.u##item=im.u##item)
    WHERE cnt > 1
    But I tried It show not valid identifier.You can't use the table aliases from the sub-query...
    SELECT item,
           mfg_item,
           manufacturer,
           description 
    FROM (SELECT it.item,
           im.mfg_item,
           im.manufacturer,
           im.description,
           count(it.item) over(partition by it.item order by it.item) cnt
      FROM item it,item_mfg im
      WHERE it.u##item=im.u##item)
    WHERE cnt > 1

  • How to add blank page to document in progress...how to combine documents

    As a long-time pagemaker user, I'm adjusting to Pages 2. I'm creating a photo directory using various sized photos, masked with shapes, along with small captions, half-page format. My problem. How can I add pages as I go along, without all that Greek placeholder type? (My first 9 pages are 99 MB). I'm thinking of creating the document in 10-page segments, then combining them before sending to our local printer. Is there any way to avoid the underlying text page layout that seems to rule the roost?
    Thanks,
    Slang.

    Hello rotorboss,
    first the last: there is no way in Pages to link images. All objects and media you insert into a document is stored into the package folder. But you can reduce the file size if you are able to handle an image editor. I think you have inserted your images directly from iPhoto, right? This means the images are in full resolution and size. But for 99 % of all images this is far more then needed.
    Here is a post I wrote yesterday that will help you to reduce the size of your Pages document: http://discussions.apple.com/thread.jspa?messageID=2711166&#2711166. If you need more details for image editing, feel free to ask.
    To give you an example of document sizes: I am writing manuals and handbooks with 350+ pages and 300+ images (most for tutorials). Most of this images are screenshots and so they are only 72 dpi in resolution. But there are a few photos as well (the biggest is 10.5 mb in TIFF format (19.5 x 12.5 cm, 300 dpi) and I have reduced it to 4.3 mb in PNG format (19.5 x 12.5 cm, 300 dpi)). This documents have file sizes between 3 mb and 25 mb.
    The only big problem is the use of CMYK images, because PNG can't handle this color format. So you have to use JPEG with good quality setting. To give you an example: the same image I mentioned above is 13.5 mb in size as a CMYK image. As a JPEG with 100 % quality and baseline optimisation you get a file size of 4.2 mb, but JPEGs compression is not lossless. In some special motifs you will get block artifacts. So you can choose the file type you want to use.

Maybe you are looking for

  • Sap script main window related question

    hi i have a requirement to add a new column to sap script main window picking information from some table this new column is C2 and it takes reference from C1 i ahve below queries 1) is is better to add a new column to main window and increase and de

  • Desktop Manager--Media

    Every time I start Media Manager and try to do anything, it freezes. I don't get the typical "not responding".  MY CPU usage goes through the roof (75% to 100%) and just doesn't allow me do anything.  I eventually have to go in and manually stop the

  • Collect Feedback workflow with pdf documents

    Hi, Is it possible to incorporate collect feedback workflow with pdf documents ? Thanks techie

  • When I unselect music from my itunes, it still syncs to my phone

    So recently, when I've unselected music on my itunes and then re-sync my phone, it still shows up on my phone even though I've unselected it on itunes. What do I need to do to fix this?

  • Wrong result of multiplication !!!

    Hello! When i run the following code the result is wrong: double d = 3.4*3.4; System.out.println(d); System.out.println(d/2); The output is 11.559999999999999 5.779999999999999 The correct result is: 11.56 5.78 Is this a bug? When i use float the res