Question : Help with T-SQL to Self Join a table 3 times

Hello,
I've spent a lot of time trying to figure it out and look like i've hit a wall, I tried every possible join, union to join a table to get only 1 row with 2 new records

I've attached sample data and the way it should look like in the TXT file


I'm using
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
SELECT distinct * FROM (
  SELECT A.[NURS_STA]
      ,A.[RM_BED]
      ,A.[MRN]
      ,A.[NAME]
      ,A.[ADM_DATE]
      ,A.[ATN_DR]
      ,A.[LOS]
      ,A.[ACCT_NO]
      ,A.[DX0]
      ,B.[DX0] AS [DX1]
      ,C.[DX0] AS [DX2]
  FROM [Census] A
  LEFT OUTER JOIN [Census] B on A.[MRN] = B.[MRN]  
  LEFT OUTER JOIN [Census] C ON A.[MRN] = C.[MRN]

  )A
, but it joins everything with everything!

any help will be appreciated..

Thanks
Attachments:
 
sample
 

Answer : Help with T-SQL to Self Join a table 3 times

Had the same problem with R52 and T40 series. Great for the first 5 years, but 3 died with very similar circumstances. One tech told me it was the board but buy the time I found a replacement board and had it installed, I could probably buy a replacement with warranty, etc. Since it was older, that is what I did. I hope you find a better answere. Thx
Random Solutions  
 
programming4us programming4us