Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
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


like that i want for all code..is it possible pls help me out..
Posted
Comments
W Balboos, GHB 24-Aug-15 9:31am    
You should tell us three things:
1 - What is the source of the date you're putting?
2 - What have you tried, so far?
3 - Why is the Urgent?
Andy Lanng 24-Aug-15 9:31am    
that depends:
What so the dates represent?
What is the date range?
Is it just sundays you exclude?
F-ES Sitecore 24-Aug-15 9:31am    
You haven't explained the logic behind what you want. What are those characters after the ADM001 and what are the rules that dictate what they should be? We're not mind-readers, we can't look at the final solution and extrapolate the rules that get you there.
Member 11337367 24-Aug-15 9:34am    
adm001 is code and it has to repeate no of day in the month i.e august 01 to august 20.
same another code adm002 has to repeate 20 times
etc
super 24-Aug-15 9:33am    
Can you be please more specific? I am not able to understand what you want?
1. You want to create a new table with <OLD NAME> + <date>
2. What do you mean by all Code?
3. From where you get the date info?

1 solution

I would use a Recursive Common Table Expression (CTE) like so:

SQL
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:

SQL
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


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

Hope that helps ^_^
Andy
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900