select a.name,a.address into table1 from a inner join b on a.id=b.id order by b.type a.name
解决方案 »
- 求sql语句
- 请教材料采购计划表的SQL写法?
- select * from sysobjects where xtype='P'如何得到存储过程的SQL 语言?
- 为什么会多重级联或循环?
- 邹老大,帮帮小弟啊,近学习您的算法,又遇鱼梗!!!!!!
- SQL SERVER可以加密存储过程和触发器吗,或者直接加密数据库?
- 怎么最快的取表中的行数?
- 为得到以下结果 , 代码怎么写 ?
- 请教高手,如何知道sql 2000数据库的触发器是否在运行???急!!!
- 在B/S结构中如何获得本机IP地址
- 怎么将datetime类型的数据转换为float类型的
- 可否把SQL SERVER的安装也打包进自己的程序安装中去?
select a.姓名, a.住址
from 表一 a inner join 表二 b on a.编号 = b.编号
where b.分类 = ...
select a.客户姓名,a.住址 into 新表
from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
2.新表已存在
insert 新表
select a.客户姓名,a.住址
from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
----
这样????
select a.姓名,a.住址 from a,b and a.编号=b.编号 and b.分类=@变量
select b.分类,a.姓名,a.住址
from 表1 a join 表2 b on a.客户编号=b.客户编号
--表不存在时生成表
select b.分类,a.姓名,a.住址
into 新表
from 表1 a join 表2 b on a.客户编号=b.客户编号
declare tb cursor for select 分类 from 表2
open tb
fetch next from tb into @分类
while @@fetch_status=0
begin
exec('select a.姓名,a.住址 into ['+@分类+'] from 表1 a join 表2 b on a.客户编号=b.客户编号 where b.分类='''+@分类+'''')
fetch next from tb into @分类
end
close tb
deallocate tb
from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
/*
以下是将t1的数据导入到t2中的方法:
*/--1、如果表t2不存在:
--导入全部字段
select * into t2 from t1
--导入部分字段
select col1,col2,col3... into t2 from t1
--导入全部并且增加自动编号(t1中没有)字段
select identity(int,1,1) id,col1,col2,col3... into t2 from t1
--导入全部并且增加新的自动编号(t1中原来有自动编号id)字段
select identity(int,1,1) id1,cast(id as int) id2,col1,col2,col3... into t2 from t1--2、如果表t2存在:
--导入全部(注意字段的类型一样)
insert t2 select * from t1
--导入部分字段
insert t2(col1,col2,col3..) select col1,col2,col3... from t1
--表t1(id,col1,col2...),表t2(id,col1,col2...)存在,两个表中都有自动增量id。
--(1):不导入自动增量
insert t2(col1,col2...) select col1,col2... from t1
--(2):导入自动增量
set identity_insert t2 on
insert t2(id,col1,col2...) select id,col1,col2... from t1
set identity_insert t2 off