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 2008 Forums
 Transact-SQL (2008)
 Loop vs. UNION denormalize - Performance

Author  Topic 

bherrok
Starting Member

2 Posts

Posted - 2009-10-28 : 02:53:32
Hi guys,

In 1 of the enterprise source systems, monthly data is stored denormalized -having 31 columns (for every day of the month) + columns for month and year and other description columns.

I'm trying to normalize the data and I'm wondering whether 31 union statements would perform better than a while loop.

I did a bit of hunting around in regards to union statements but couldn't find any hard evidence supporting union and parallel queries, especially to do with performance...

Any experts can shed some light or have done this test before?

Thanks in advanced.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-10-28 : 06:53:20
There's also the UNPIVOT statement added since SQL 2005. Try that first.

If you do use UNION, go with UNION ALL, unless you know you'll end up with duplicates you don't want.
Go to Top of Page

bherrok
Starting Member

2 Posts

Posted - 2009-10-28 : 17:39:25
ah! yes... forgot about that 1. been working in SQL 2000 (still) for a while.

You'd think unpivot would be optimized and therefore better than while loop and union.

Thanks for the quick reply robvolk!

quote:
Originally posted by robvolk

There's also the UNPIVOT statement added since SQL 2005. Try that first.

If you do use UNION, go with UNION ALL, unless you know you'll end up with duplicates you don't want.

Go to Top of Page
   

- Advertisement -