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
 SQL Server Development (2000)
 Dynamic Columns

Author  Topic 

vipul_parekh_b
Starting Member

4 Posts

Posted - 2007-09-04 : 04:04:05
Hi All,

I have this report to be generated, and I have decided to do it by pure sql query with out any front end loop.

Here is what I want.

Invoice No.(unique) Invoive Date Client Name Tax1 Tax2 Tax3 Tax4 .......

Now here you saw that there are certain columns which are fix (Invoice No. Invoive Date Client Name) and there's no big deal getting them.

The real problem starts with Tax columns. In some invoices there can be tax1 and not tax2, in another invoice there can be tax3 and not tax1-2.

Any invoice can have as many tax as they can. Hence there's no fix number of tax which I can play around.

I hope I have explain it better.

Vipul Parekh

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-04 : 04:08:23
You need a dynamic CROSSTAB or PIVOT query.
There are many if them available.

Here is a start
http://www.sqlservercentral.com/columnists/plarsson/pivottableformicrosoftsqlserver.asp



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -