不明白楼主什么意思.我的理解是:
insert into tableName(field1)
select field1
from ....
其中field1是主键,但检索出来的结果field1不唯一。那么你可以用select distinct替换select。
insert into tableName(field1)
select field1
from ....
其中field1是主键,但检索出来的结果field1不唯一。那么你可以用select distinct替换select。
解决方案 »
- 求 SQL server 2008 把列内容大小写转换语句
- 设计商品子系统的存储结构或数据库结构(求助,在线等)
- 远程删除数据时的where条件中含有子查询时报错
- ASP+SQL2005存储过程问题
- 头一次发贴,请多支持(SSIS包的配置问题)
- 安装Microsoft SQL Server 2005 Express Edition的问题,急!!!!哪位高手帮帮忙!
- 加50分,关注一下.日期做字段名的问题!
- 我用asp连接sql server总是失败,请问哪里有关于这方面的资料下载吗?或者请哪位高手给我说说应该怎么连接!谢谢!
- 求购有关sql server2000存储过程、触发器及视图的例子、资料和书下载??在线等待!!
- 有关临时表的问题:我在sql server的storedproc中创建一临时表,可在asp中却找不到!
- 关于合并2个表为一个表的问题!
- 各位高手老师兄弟姐妹,SQL Server Enterprise Manager.msc 不见了,救命啊!
insert只插入第一条:insert into table2
select top 1 *
from table1
where ...
table结构如下:(education)
wno,major,schoolname,begindate,enddate,
其中wno,major & begindate为关键字
现在我需要把一临时table中的4条记录插入到education中
wno major schoolname begindate enddate
'0209402','computer','苏州大学',19970901, 20010701
'0209402','computer','东北大学',19970901, 20020701
'0209402','english', '东北大学',20010901, 20030701
'0209407','chinese', '东北大学',20010901, 20030701
其中1,2的关键字相同,不知如何处理.to 这样的话,可以用异常处理来实现呀,如果是关键字重覆了,就不再insert
如何实现啊.
您的意思是在存储过程中用游标定位纪录,然后逐个插入吗?有没有办法一条sql语句实现?
关注中...
在前台的话需要加入错误异常处理
游标很简单,还是使用游标吧。用游标出错处理如何写了,因为现在它还是会包错啊
Declare cur cursor
for select distinct * from #f
for read only
open cur fetch next from cur into @wno,@type,@proficiency
while @@error=0
begin
Insert Into bqp..language (wno , type , proficiency) Values (@wno , @type , @proficiency)
end
if (@@error<>0)
rollback tran
FETCH NEXT FROM cur
into @wno,@type,@proficiency close cur
deallocate cur以上是我写的游标
Declare cur cursor
for select distinct [Employee Number],[Language Type],Proficiency from [Speciality$]
open cur
-- on error resume next
fetch next from cur into @wno,@type,@proficiency
begin tran
while @@FETCH_STATUS=0 begin
Insert Into bqp..language (wno , type , proficiency) Values (@wno , @type , @proficiency)
FETCH NEXT FROM cur into @wno,@type,@proficiency
print @@error
print @@rowcount
IF @@error != 0 OR @@rowcount != 1
begin
print @@error
rollback tran
--close cur
--DEALLOCATE curselect *
--return
end
endclose cur
commit tran
DEALLOCATE cur已经搞定了,你们给答案真是模糊啊