0

Hello and thanks for your attention

I need to convert data from two different lines into one line.

Let s imagine

ORDERS table:

ID    Name    adress   
-------------------- 
01    AA      adr1
02    BB      adr2
03    CC      adr3

LINEORDERS table:

ID    IDorder    IDprofileType     ProfileType      idPers   
------------------------------------------------------------- 
01    01         01                Organizer        0045
01    01         02                Present          0085
01    01         02                Present          0032
01    01         03                Manager          0018

Lets imagine we want as result >

Desired result:

IDorder   NameOrder     OrganizerID           PresentID           ManagerID       Diff
------------------------------------------------------------- 
01        AA            0045                  0085                0018            yes
01        AA            0045                  0032                0018            yes

Diff is yes if managerID and organizerID are different.

How can I get such a result?

Do I need to create T-SQL temporary tables? What would be the lighter?

I have a lot of lines in the table.

Thanks for your help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

You can achieve this with subqueries, but I really think that you must do some reengineering here. Cause there will be a lot of subqueries.

Darthman
  • 457
  • 4
  • 21
0

If you are using MS SQL Server, you should try PIVOT. Here are some examples: SQL Server: Examples of PIVOTing String data

Community
  • 1
  • 1
Pavel Kudinov
  • 405
  • 2
  • 8