SQL Server - Insert into a combination of two tables -


i need combinate 2 tables in sql server. need have row each item of table each item of table b, resulting in table c. this:

table a b c d  table b 1 2 3  table c column x | cloumn y              1              2              3    b           1    b           2     b           3    c           1    c           2    c           3    d           1    d           2    d           3 

thanks all!

you can this:

select   a.a + cast(b varchar(2)) tablea cross join tableb b; 

see in action:

then can use into clause insert them table exists:

insert tablec(c) select   a.a + cast( b varchar(2)) tablea cross join tableb b; 

or create new table these values:

select   a.a + cast( b varchar(2)) c tablec tablea cross join tableb b; 

updated sql fiddle demo

note that: assumed columns' names, since didn't specify them in question.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -