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.
Author |
Topic |
besadmin
Posting Yak Master
116 Posts |
Posted - 2009-05-14 : 17:28:54
|
hey friends, just as an example this is what i want to do.i have a table with 1 column values (1, 2, 3, 4)i have another table with 1 column (a, b, c, d)how do i query to do 1a, 1b, 1c, 1d2a, 2b, 2c, 2d.Thanks for any help friends! |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-14 : 22:18:19
|
[code]select t1.col + t2.colfrom table1 t1 cross join table2 t2[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-15 : 14:40:57
|
if ist tables column is of type int remember to cast it to varchar before concatenationselect cast(t1.col as varchar(10)) + t2.colfrom table1 t1 cross join table2 t2 |
|
|
besadmin
Posting Yak Master
116 Posts |
Posted - 2009-05-19 : 18:40:38
|
Hey, Thanks a ton guys!Your method definatley provided the example for what we were trying to do. Thanks!Another way besides Cross Join my manager found was using like t1, t2like thisSELECT Letter.Letter + Number.Num AS NumAndLetterFROM Letter, Number Do you see any downside for using that, or benefits of using the CROSS JOIN over each other?The CROSS JOIN I haven't seen before, it's nice!Thanks again to both of you!!LAter, |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2009-05-21 : 07:44:09
|
It's the same. Check the query plan if you need convincing! |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-05-21 : 08:43:28
|
yes it *is* the same but at some point support for non ANSI JOINs will be removed from SQLserver.I have no idea when this will be.It's safer and more readable to use the CROSS JOIN syntax.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
|
|
|
|
|