Sql查询问题

Dision LI Dision LI 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

--检查临时表
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempwk'))
Drop table #tempwk
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempPer'))
Drop table #tempPer
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempList'))
Drop table #tempList


-- 周一开始
select fDate into #tempwk from (
select DATEADD(wk,DATEDIFF(wk,0,getdate()),0) fDate
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),1)
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),2)
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),3)
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),4)
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),5)
union
select DATEADD(wk,DATEDIFF(wk,0,getdate()),6)
) T
--人员
select fName into #tempPer from (
select '张三' fName
union
select '李四'
) T

select fDate, fName into #tempList from #tempwk,#tempPer
--人员
insert into #tempPer(fName) values('王五')
--周人员列表
insert into #tempList(fName,fDate) values('王五','2013-04-22')

insert into #tempList
select fDate, fName from #tempwk,#tempPer
where ???(这里如何不重复插入数据 1.张三、李四不重复插入 2.王五 22号不重复插入)

select * from #tempList


...全文
评论 1
收藏 已收藏
分享
返回顶部
Dision LI
MS-SQL Server 34,877 成员 254,635 内容