Hello, I've done something like this before, you can create a temp table for
your output (If you know how many possible name_type values there are),
and then do an update using a:
Create #tmpOut with all required fields (Each possible name_type field)
--seed the table with the appropriate party_id's
insert into #tmpOut (party_ID) (select distinct Party_id from mainTable)
update #tmpOut set
lnme =
case name_type
when 'lnme' then
mainTable.name
else
#tmpOut.lname
end
....repeat for each field
from mainTable where party_id=#tmpOut.party_id
Or something along those lines, (I don't have time to actually test it out,
and it probably has syntax errors. I've been doing VB6, VB.Net, C#, and
Java recently, and I get the syntax screwed up all the time if I don't have
the IDE running, and showing me the pretty colors sorry :-)
Also, you may be able to dynamically create the table, and the appropriate
Case statements for each field, and then run it as a Dynamic SQL using Exec
@SQLQuery, I doubt the performance would be too bad.
Also, you can probably do something similar using OLAP, but I haven't used
OLAP for several years, and I don't recall how to do all the stuff.
I have never used SQL 2005 Beta, but if it does Pivot Tables, that will be
great! I can't wait to try it out.
I bet there are 50 ways to do it better than I've told you, but hopefully
this will give you a couple ideas to get started anyway.
Good Luck
Lance
[quoted text, click to view] "fredy" <anonymous@discussions.microsoft.com> wrote in message
news:9cdb01c486b3$2a3c0120$a401280a@phx.gbl...
How can I convert to horizontal records the following data:
party_id name_type name
-------- --------- ---------------------
1 lnme Smith
1 nme Jhon
1 alias Jhonny
2 lnme Hernandez
2 nme Fredy
2 title Mr.
I want to have the data as follow
party Id title lnme nme alias
-------- ----- ----------- ----------- ------
1 Smith Jhon Jhonny
2 Mr. Hernandez Fredy