本文介绍了如何把日期与其他值...请解决这个非常紧急..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子

喜欢

ex:

code

ADM001

DGM004

DyZ001

DyZ002

DZM002

DZM006

DZM007

DZM008







等等



我想在下面制作一张桌子

格式

代码日期

ADM001 01-08 -2015

ADM001 03-08-2015

ADM001 04-08-2015

ADM001 05-08-2015

ADM001 06-08-2015

ADM001 07-08-2015

ADM001 08-08-2015

ADM001 10-08-2015

ADM001 11-08-2015

ADM001 12-08-2015

ADM001 13-08-2015

ADM001 14-08-2015

ADM001 15-08-2015

ADM001 17-08-2015

ADM001 18-08-2015

ADM001 19-08-2015

ADM001 20-08-2015

DZM026

DZM028

GM0001

GM0002

RM0008

RM0009





就像我想要的所有代码..它可能请帮助我..

I have one table
like
ex:
code
ADM001
DGM004
DyZ001
DyZ002
DZM002
DZM006
DZM007
DZM008
.
.
.
so on

I want to make one table like in below
format
code Date
ADM00101-08-2015
ADM00103-08-2015
ADM00104-08-2015
ADM00105-08-2015
ADM00106-08-2015
ADM00107-08-2015
ADM00108-08-2015
ADM00110-08-2015
ADM00111-08-2015
ADM00112-08-2015
ADM00113-08-2015
ADM00114-08-2015
ADM00115-08-2015
ADM00117-08-2015
ADM00118-08-2015
ADM00119-08-2015
ADM00120-08-2015
DZM026
DZM028
GM0001
GM0002
RM0008
RM0009


like that i want for all code..is it possible pls help me out..

推荐答案

declare @start date, @end date

set @start = '01 aug 2015'
set @end = '20 aug 2015'
;
with dates as (
  select @start [date]
  union all
  select dateadd(day,1,[date])
  from dates
  where [date] < @end
  )
select * from dates
--exclude sundays:
where datepart(weekday,[date]) > 1





您可以将此加入您的其他桌面,不受任何条件限制所以:





You can join this to your other table without any conditions like so:

declare @start date, @end date

set @start = '01 aug 2015'
set @end = '20 aug 2015'
;
with dates as (
  select @start [date]
  union all
  select dateadd(day,1,[date])
  from dates
  where [date] < @end
  )
select codes.code,dates.date from dates , codes 
where datepart(weekday,[date]) > 1





这将显示您的所有代码,每个代码都包含所有代码日期



希望有所帮助^ _ ^

Andy



this will show all of your codes, each with all of the dates

Hope that helps ^_^
Andy


这篇关于如何把日期与其他值...请解决这个非常紧急..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:12