一,select id FROM 表A where 网站名称='搜热网',取ID
二,INSERTINTO 表B ('网站名称','ID','地址') VALUES ('搜热网','ID','http://soohot.com') 因为这里的ID是变量,不知道用Set @ID能不能实现!
不知道怎么使用存储过程,所以请教!!
declare @id varchar(200)
select @id=id FROM 表A where 网站名称='搜热网'
INSERT INTO 表B (网站名称,ID,地址) VALUES ('搜热网',@id,'http://soohot.com')
或
insert into 表B(网站名称,ID,地址)
select '搜热网',id,'http://soohot.com'
from 表A where 表A.网站名称='搜热网'
两者都提示错误,请教了!!
二,INSERTINTO 表B ('网站名称','ID','地址') VALUES ('搜热网','ID','http://soohot.com') 因为这里的ID是变量,不知道用Set @ID能不能实现!
不知道怎么使用存储过程,所以请教!!
declare @id varchar(200)
select @id=id FROM 表A where 网站名称='搜热网'
INSERT INTO 表B (网站名称,ID,地址) VALUES ('搜热网',@id,'http://soohot.com')
或
insert into 表B(网站名称,ID,地址)
select '搜热网',id,'http://soohot.com'
from 表A where 表A.网站名称='搜热网'
两者都提示错误,请教了!!
select @id = top 1 id FROM 表A where 网站名称 = '搜热网'
if @id is not null
INSERT INTO 表B (网站名称 , ID , 地址) VALUES ('搜热网' , @id ,'http://soohot.com')
declare @id varchar(200)
select @id = top 1 id FROM 表A where 网站名称 = '搜热网'
if @id is not null
INSERT INTO 表B (网站名称 , ID , 地址) VALUES ('搜热网' , @id , 'http://soohot.com')--多个ID
insert into 表B(网站名称 , ID , 地址)
select 网站名称 = '搜热网' , ID , 地址 = 'http://soohot.com' from A where 网站名称 = '搜热网'
insert into @a select 1,'搜热网','www.kk.com'
declare @b table(id int,name varchar(20),addr varchar(20))
declare @name varchar(20),@id int
set @name='搜热网'
select @id=id from @a where name=@name
insert into @b(id,name,addr) select id,name,addr from @a where id=@idselect * from @b