SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CROSS JOIN
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vijays3
Constraint Violating Yak Guru

India
343 Posts

Posted - 12/05/2013 :  09:38:53  Show Profile  Reply with Quote
Hi All,

I am stuck in a situation where I am trying to use CROSS JOIN.
But this not solving my problem at all.I am using example to
show my problem.


Declare @a table( a int)
INSERT into @a values (1)

Declare @b table( b int)
INSERT into @b VALUEs(2)

Declare @c table( c int)
INSERT into @c VALUEs(3)

SELECT t1.a,t2.b,t3.c from @a t1 CROSS JOIN
@b t2 CROSS JOIN @c t3

Above script gives me correct information like

a b c
1 2 3

But the Problem is if any of the table is blank it does
not return any thing for example


Declare @a table( a int)
INSERT into @a values (1)

Declare @b table( b int)
--INSERT into @b VALUEs(2)

Declare @c table( c int)
INSERT into @c VALUEs(3)

SELECT t1.a,t2.b,t3.c from @a t1 CROSS JOIN
@b t2 CROSS JOIN @c t3


Table @b is empty and this Select query gives
nothing.
How can I fix this even after any of the table is blank
I should get the column with NULL or blank value.





Vijay is here to learn something from you guys.

Ifor
Aged Yak Warrior

588 Posts

Posted - 12/05/2013 :  09:49:20  Show Profile  Reply with Quote
This is what CROSS JOIN is meant to do.

It is difficult to tell, but maybe you want a FULL JOIN:

SELECT t1.a,t2.b,t3.c
from @a t1
	FULL JOIN @b t2 ON 1=1
	FULL JOIN @c t3 ON 1=1
Go to Top of Page

vijays3
Constraint Violating Yak Guru

India
343 Posts

Posted - 12/05/2013 :  09:56:45  Show Profile  Reply with Quote
Thanks Ifor.That's what I wanted to get

Vijay is here to learn something from you guys.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000