Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Control Structure

Author  Topic 

sneupane
Starting Member

28 Posts

Posted - 2011-11-08 : 19:27:19
I have a data set Table X and Table Y

Table X
------------

Category
A
B
C

Table Y
-------------
Name ID
Robert 23
Carlos 35
Steve 40

I was trying to get like shown below;
Category Name ID
A Robert 23
A Carlos 35
A Steve 40
B Robert 23
B Carlos 35
B Steve 40
C Robert 23
C Carlos 35
C Steve 40

I just could not get a proper control statement to get it work. Any help would be appreciated.
Thanks
Sar




Sar

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-08 : 19:31:18
Looks like you want to use CROSS JOIN to get a cartesian product. Have you tried that?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sneupane
Starting Member

28 Posts

Posted - 2011-11-08 : 19:48:04
this should be it..great thanks.. oops i was thinking of using a control loop that starts from taking the value "A" and putting along the records for Name and ID. After completing for A it goes to B and so on... is there any way to proceed like this.. kinda curious for my knowledge..

Sar
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-08 : 20:21:44
quote:
Originally posted by sneupane

this should be it..great thanks.. oops i was thinking of using a control loop that starts from taking the value "A" and putting along the records for Name and ID. After completing for A it goes to B and so on... is there any way to proceed like this.. kinda curious for my knowledge..

Sar


That will be using a cursor or while loop. It will required more coding


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-08 : 21:29:16
quote:
Originally posted by khtan

quote:
Originally posted by sneupane

this should be it..great thanks.. oops i was thinking of using a control loop that starts from taking the value "A" and putting along the records for Name and ID. After completing for A it goes to B and so on... is there any way to proceed like this.. kinda curious for my knowledge..

Sar


That will be using a cursor or while loop. It will required more coding


KH
[spoiler]Time is always against us[/spoiler]





And performance will be bad.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -