[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Problem with sorting data in Full Outer Join Table

MacChojnacki@googlemail.com

3/15/2007 2:03:00 PM

Hello,
I stucked on strange problem with data order in dataset.
Any clue or suggests will be appreciated.
Let's start from the beggining. We have to tables:

Table1:
Nr1
21
22
23
24
25
26
27
28
35
37


Table2:
Nr2
20
21
22
25
26
28
32
34
39


This is my result which doesn't statisfy me:
Nr1 Nr2
21 21
22 22
23 0
24 0
25 25
26 26
27 0
28 28
35 0
37 0
0 32
0 39
0 20
0 34



The Code:
SELECT TOP 100 PERCENT dbo.temp1.[Nr1], dbo.temp2.[Nr2]
FROM dbo.temp1 FULL OUTER JOIN
dbo.temp2 ON dbo.temp1.[Nr1] = dbo.temp2.[Nr2]


As you can see there are some problems with sorting in second column.
I would like to get the result like below:

Nr1 Nr2
0 20
21 21
22 22
23 0
24 0
25 25
26 26
27 0
28 28
0 32
35 0
37 0
0 34
0 39


So I'm begging you for any help :)
Thanks in advance!

1 Answer

Jim Underwood

3/15/2007 3:27:00 PM

0

Try using coalesce in your order by. You show "0" in your results, but I am
assuming that you really have nulls, based on your sql?

order by coalesce(dbo.temp1.[Nr1], dbo.temp2.[Nr2])

<MacChojnacki@googlemail.com> wrote in message
news:1173967388.167695.81740@b75g2000hsg.googlegroups.com...
> Hello,
> I stucked on strange problem with data order in dataset.
> Any clue or suggests will be appreciated.
> Let's start from the beggining. We have to tables:
>
> Table1:
> Nr1
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 35
> 37
>
>
> Table2:
> Nr2
> 20
> 21
> 22
> 25
> 26
> 28
> 32
> 34
> 39
>
>
> This is my result which doesn't statisfy me:
> Nr1 Nr2
> 21 21
> 22 22
> 23 0
> 24 0
> 25 25
> 26 26
> 27 0
> 28 28
> 35 0
> 37 0
> 0 32
> 0 39
> 0 20
> 0 34
>
>
>
> The Code:
> SELECT TOP 100 PERCENT dbo.temp1.[Nr1], dbo.temp2.[Nr2]
> FROM dbo.temp1 FULL OUTER JOIN
> dbo.temp2 ON dbo.temp1.[Nr1] = dbo.temp2.[Nr2]
>
>
> As you can see there are some problems with sorting in second column.
> I would like to get the result like below:
>
> Nr1 Nr2
> 0 20
> 21 21
> 22 22
> 23 0
> 24 0
> 25 25
> 26 26
> 27 0
> 28 28
> 0 32
> 35 0
> 37 0
> 0 34
> 0 39
>
>
> So I'm begging you for any help :)
> Thanks in advance!
>