johnsql
Posting Yak Master
161 Posts |
Posted - 2007-10-01 : 09:25:55
|
I make a table variable and I'd like to insert to insert 6 rows into that table using SELECT statements. If I use UNION only, I get only 5 rows inserted. If I use UNION ALL, I get 6 rows inserted. So, please tell me why UNION does not work correctly?declare @sample table (ID int, TIME_SPENT int, [DATE] datetime, DAY_LENGTH int, TOTAL_AUMONT money)-- only 5 rows inserted if using UNIONinsert @sampleselect 11516, 60, '27-Sep-07', 510, 7.5union select 11516, 15, '27-Sep-07', 510, 8.25union select 11516, 30, '27-Sep-07', 510, 8union select 11846, 30, '27-Sep-07', 480, 7.5union select 11846, 15, '27-Sep-07', 480, 7.75union select 11846, 30, '27-Sep-07', 480, 7.5-- 6 rows inserted if using UNION ALLdeclare @sample table (ID int, TIME_SPENT int, [DATE] datetime, DAY_LENGTH int, TOTAL_AUMONT money)insert @sampleselect 11516, 60, '27-Sep-07', 510, 7.5union all select 11516, 15, '27-Sep-07', 510, 8.25union all select 11516, 30, '27-Sep-07', 510, 8union all select 11846, 30, '27-Sep-07', 480, 7.5union all select 11846, 15, '27-Sep-07', 480, 7.75union all select 11846, 30, '27-Sep-07', 480, 7.5Thanks in advance.johnsql |
|