select出来后怎么添加n条记录呀?select telphone,email into temp from users join users on temp.user=users.user会自动对应相关记录吗?
1.先把记录放到表变量中 declare @temp1 table ( user varchar(8), lognum varchar(8), telephone varchar(8), email varchar(8) ) Insert into @temp1(...自己写吧) select ...自己写吧 FROM user,#temp where ...自己写吧 2.修改临时表的结构 alert #temp (...自己写吧) 3.将数据从表变量插入到临时表 declare @count int declare @i int set @i=1 set @count=select count(*) from @temp1 while @i<=@count begin insert into #temp values(...自己写吧) set @i=@i+1 end 搞定了,觉得有用记得给分
declare @temp1 table
(
user varchar(8),
lognum varchar(8),
telephone varchar(8),
email varchar(8)
)
Insert into @temp1(...自己写吧)
select ...自己写吧 FROM user,#temp where ...自己写吧
2.修改临时表的结构
alert #temp
(...自己写吧)
3.将数据从表变量插入到临时表
declare @count int
declare @i int
set @i=1
set @count=select count(*) from @temp1
while @i<=@count
begin
insert into #temp values(...自己写吧)
set @i=@i+1
end
搞定了,觉得有用记得给分
B 20
C 20用户表usersuser telphone email
A 11 [email protected]
B 22 [email protected]
C 33 [email protected] a.*,b.telphone,b.email from temp a
left join users b on a.user=b.user