我用select查询出来的结果集,想在结果集上再加上一列,这一列的值全是我指定的一个字符串,然后插入数据库去,这样的语句要怎么写?例:表A:
Col1 Col2 Col3
1 1-1 1-2
2 2-1 2-2用 select * from A得出结果集再加上一列然后插入到表B:表B结果:
Col1 Col2 Col3 Col4
1 1-1 1-2 OK
2 2-1 2-2 OK我不知道怎么在结果集上再插入一列然后设置值
还有一个:在SQL 2000上存储过程可以用“表参数”吗?
Col1 Col2 Col3
1 1-1 1-2
2 2-1 2-2用 select * from A得出结果集再加上一列然后插入到表B:表B结果:
Col1 Col2 Col3 Col4
1 1-1 1-2 OK
2 2-1 2-2 OK我不知道怎么在结果集上再插入一列然后设置值
还有一个:在SQL 2000上存储过程可以用“表参数”吗?
解决方案 »
- 按月统计总数
- 菜鸟提问! trigger可不可以跨服务器访问操作啊 急!!!!!!
- 求:最小时间的记录
- 关于decimal浮点数的问题,我想把一个计算过程保存起来,直接print 出来的结果是正确的,为什么转换一下就错了?谢谢!
- 进行SQL Server数据库操作时,如何直接捕获到SQL Server错误消息代码
- HELP: 怎样将SQL SERVER表里的数据导入到Access表中?
- Sql Server 的连接问题
- 关于数据的保存!
- 如何对一个Access文件设置为一个只读属性,并且从此属性设置不可被修改。
- 后台数据库sql2000中datetime字段,如何建立一个默认值
- convert转换时间类型出错
- 请教SQL2005如何新创建一个Instance
insert into b
select *,'OK' as col4
from a
存储过程可以使用表变量!
--字段多了限定下
insert into b(col1,col2,col3,col4)
select col1,col2,col3,'OK' as col4
from a
declare @t table(id int)
insert into #t select 1update @t set id = 2--...
创建一个零时表 create table #a(id , Col4)
重复的话
insert into b
select col1,col2,col3,'OK' from a或者先insert b
select col1,col2,col3 from a
然后再update
declare @表A table (Col1 int,Col2 varchar(3),Col3 varchar(3))
insert into @表A
select 1,'1-1','1-2' union all
select 2,'2-1','2-2'select *,'OK' as col4 into #表B from @表Aselect * from #表B
/*
Col1 Col2 Col3 col4
----------- ---- ---- ----
1 1-1 1-2 OK
2 2-1 2-2 OK
*/
drop table #表B
create table tb(Col1 int,Col2 varchar(3),Col3 varchar(3))
insert into tb
select 1,'1-1','1-2' union all
select 2,'2-1','2-2'create proc pr_name(@str varchar(10))
as
begin
select *,@str as col4 from tb
endexec pr_name 'ok'/*
Col1 Col2 Col3 col4
----------- ---- ---- ----------
1 1-1 1-2 ok
2 2-1 2-2 ok(2 行受影响)