CREATE PROCEDURE Users_Data
@user_name char(20)='%'
AS
declare @yhm char(20)
declare @zcrq datetime
create table tempdate
(
yhm char(20),
consume int,
zcrq datetime
)begin
insert into tempdate(yhm,consume,zcrq)
select distinct yhb_yhm,'0',yhb_zcrq from dh_yhb order by yhb_zcrq desc
enddrop table tempdateGO我用select distinct yhb_yhm,'0',yhb_zcrq from dh_yhb order by yhb_zcrq desc查出来的数据有三条,为什么只插入了一条啊
@user_name char(20)='%'
AS
declare @yhm char(20)
declare @zcrq datetime
create table tempdate
(
yhm char(20),
consume int,
zcrq datetime
)begin
insert into tempdate(yhm,consume,zcrq)
select distinct yhb_yhm,'0',yhb_zcrq from dh_yhb order by yhb_zcrq desc
enddrop table tempdateGO我用select distinct yhb_yhm,'0',yhb_zcrq from dh_yhb order by yhb_zcrq desc查出来的数据有三条,为什么只插入了一条啊
select distinct yhb_yhm,'0',yhb_zcrq from dh_yhb order by yhb_zcrq desc
执行一次插入一条记录
SELECT field1[, field2[, ...]] INTO新表 FROM源
CREATE PROCEDURE Users_Data
@user_name char(20)='%'
AS
declare @yhm char(20)
declare @zcrq datetime
select distinct yhb_yhm,'0',yhb_zcrq into tempdate from dh_yhb order by yhb_zcrq desc
drop table tempdate注意:select into语句本身就会建立目的数据表,所以不必事先建立临时表