insert into com select 1001,'sun','120'中 select的作用是什么 ---SELECT 子查询
他是把select查到的数据插入到com表
查询到的数据可以做为一个表处理 看看我的例子select m.item,item.description,iv.vend_num, sum(case when m.qty>0 then isnull(m.qty,0) else 0 end) as Rec_Qty,sum(case when m.qty<0 then isnull(m.qty,0) else 0 end) as Rr_Qty from matltran m left join item on m.item=item.item left join (select item,vend_num from itemvend where rank='1') iv on m.item=iv.item where m.trans_type in('R','W') and iv.vend_num<>NULL and convert(varchar(10),m.trans_date,120) between convert(varchar(10),@Starttrans_date,120) and convert(varchar(10),@Endtrans_date,120) and m.item>=isnull(@Startitem,m.item) and m.item<=isnull(@Enditem,m.item) group by m.item,item.description,iv.vend_num select * from matltran where item='HB40044-12S' AND trans_type in('R','W') AND convert(varchar(10),trans_date,120) between '2008-10-01' and '2008-10-30'
---SELECT 子查询
看看我的例子select m.item,item.description,iv.vend_num, sum(case when m.qty>0 then isnull(m.qty,0) else 0 end) as Rec_Qty,sum(case when m.qty<0 then isnull(m.qty,0) else 0 end) as Rr_Qty
from matltran m
left join item on m.item=item.item
left join (select item,vend_num
from itemvend
where rank='1') iv on m.item=iv.item
where m.trans_type in('R','W') and iv.vend_num<>NULL
and convert(varchar(10),m.trans_date,120) between convert(varchar(10),@Starttrans_date,120)
and convert(varchar(10),@Endtrans_date,120)
and m.item>=isnull(@Startitem,m.item)
and m.item<=isnull(@Enditem,m.item)
group by m.item,item.description,iv.vend_num
select *
from matltran
where item='HB40044-12S'
AND trans_type in('R','W')
AND convert(varchar(10),trans_date,120) between '2008-10-01' and '2008-10-30'