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 2005 Forums
 Transact-SQL (2005)
 Little help with pivot function

Author  Topic 

vsempoux09
Starting Member

3 Posts

Posted - 2009-06-23 : 03:22:21
Hello all,

I'm having a little trouble with (a new function for me) the pivot statement.
Let me give you a quick overview of my problem.
I have two tables (order and tracking).
In my order table i have various columns:
UID (unique id)
owner (responsable for this order)
creationDate
status
company
...
There is a customizable tracking system which will record all
changes on predefined fields and logs that in the tracking table.
The tracking table has the following columns
UID
recordID (uid of the order record)
changedate (date when the change occurs)
changefields (field on which the tracking is triggered, in this case status )
oldValue (value of the status before the change)
newvalue (value of the status after the change)
user (user who did the change)

My problem is now that i want to list (in one line) all the changes that have already occured until today

i have been strugling quite some time with this, but i'm stuck.
Could anyone give me some pointers, tips, .. to help me out.

thanks in advance.


Greetings,
Vincent

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-23 : 03:31:47
Do you also have an example of the preferred result?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

vsempoux09
Starting Member

3 Posts

Posted - 2009-06-23 : 03:50:51
Hi,

Thanks for the quick reply.

The output should look something like this :

order.uid, order.ref, order.owner, order.status, order.company,
tracker.changedate, tracker.user, tracker.oldvalue, tracker.newvalue, tracker.changedate, tracker.user, tracker.oldvalue,
tracker.newvalue, ... (and this as many times repeated that there are records in the tracker for the unique order id).

Is this possible ?

Greetings,
Vincent
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-23 : 03:55:31
Yes.
Use INNER JOIN to tie the two tables together.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

vsempoux09
Starting Member

3 Posts

Posted - 2009-06-23 : 04:38:08
Hi,

The inner join gives me a multiple line result (on line per entry in the tracker).
The result i'm looking for should be in one line.

Greetings,
Vincent
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-23 : 04:47:47
see this link
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
or post some sample data and sample output
Go to Top of Page
   

- Advertisement -