Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Duplicate row returned based on column value

Author  Topic 

liffey
Yak Posting Veteran

58 Posts

Posted - 2005-01-27 : 05:10:50
Does the topic heading make sense?

What I wish ti achieve is to return 2 copies of a row based on the value of a field in the original row.

e.g.
Rows in table:
number, name, value
123, John, 0
234, Tom, 1

Returned rows:
123, John, 0
234, Tom, 1
234, Tom, 1

Although there are only 2 rows in the original table I need 3 rows returned. Because the value field is 1 I want 2 copies of that row.

The reason for this approach is that I am using a 3rd party reporting tool to print invoices. Some clients require 2 copies of an invoice. A flag on the clients account is used to denote this requirement.

By using this method the 2 invoices will print together and save having to pass against the file a second time. My original thought was to set ...PrinterSettings.Copies = 2 but the reporting engine does not handle this very cleanly.

Any suggestions? Thanks in advance.



-dw

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2005-01-27 : 06:51:33
Try using: UNION ALL

select * from tableName
union all
select * from tableName where [value] = 1

Hope it helps.
Go to Top of Page

liffey
Yak Posting Veteran

58 Posts

Posted - 2005-01-27 : 06:57:35
Thanks YellowBug, just what I needed. It gives me exactly what I am looking for.

Declan



-dw
Go to Top of Page

liffey
Yak Posting Veteran

58 Posts

Posted - 2005-01-27 : 07:04:41
One more question if I may!

How do I sort the resulting dataset?

ORDERB BY ??? following the second select statement?

-dw
Go to Top of Page
   

- Advertisement -