Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8691053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:02:34+00:00 2026-06-13T00:02:34+00:00

I have below 2 tables Table1 Plant —– TRP1 DEP1 Table2 Config —— 84ROC20

  • 0

I have below 2 tables

Table1

 Plant      
 -----
 TRP1
 DEP1

Table2

Config
------
84ROC20
100ROC20

and 2 textboxes

1.Start date(datetime) : 2012-08-01 00:00:00.000

2.Enddate(datetime):2012-10-01 00:00:00.000

I want to have below table as a result with 3 columns

Plant  Config    Time
-----  ------   -------
TRP1   84ROC20   2012-08-01 00:00:00.000 
TRP1   84ROC20   2012-09-01 00:00:00.000 
TRP1   84ROC20   2012-10-01 00:00:00.000
DEP1   84ROC20   2012-08-01 00:00:00.000 
DEP1   84ROC20   2012-09-01 00:00:00.000
DEP1   84ROC20   2012-10-01 00:00:00.000
TRP1   100ROC20  2012-08-01 00:00:00.000
TRP1   100ROC20  2012-09-01 00:00:00.000 
TRP1   100ROC20  2012-10-01 00:00:00.000
DEP1   100ROC20  2012-08-01 00:00:00.000 
DEP1   100ROC20  2012-09-01 00:00:00.000
DEP1   100ROC20  2012-10-01 00:00:00.000

Can you please help to have this table

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:02:35+00:00Added an answer on June 13, 2026 at 12:02 am

    I’m assuming SQL Server 2005+ (using a recursive CTE for convenience), but this should help you out:

    -- Get user data
    declare @StartDate datetime = '2012-08-01'
    declare @EndDate datetime = '2012-10-01'
    
    -- Actual query
    ;with Dates as ( -- Build a date table based upon the user values
        select @StartDate as DateEntry -- Start at StartDate
        union all
        select dateadd(m, 1, DateEntry) -- Recursively add a month
        from Dates
        where dateadd(m, 1, DateEntry) <= @EndDate -- Until the EndDate is reached
    )
    select *
    from Plant, Config, Dates -- Cross-join all tables to get all possibilities
    order by Config desc, Plant desc, DateEntry
    

    This will give the output below for your test data:

    Plant      Config     DateEntry
    ---------- ---------- -----------------------
    TRP1       84ROC20    2012-08-01 00:00:00.000
    TRP1       84ROC20    2012-09-01 00:00:00.000
    TRP1       84ROC20    2012-10-01 00:00:00.000
    DEP1       84ROC20    2012-08-01 00:00:00.000
    DEP1       84ROC20    2012-09-01 00:00:00.000
    DEP1       84ROC20    2012-10-01 00:00:00.000
    TRP1       100ROC20   2012-08-01 00:00:00.000
    TRP1       100ROC20   2012-09-01 00:00:00.000
    TRP1       100ROC20   2012-10-01 00:00:00.000
    DEP1       100ROC20   2012-08-01 00:00:00.000
    DEP1       100ROC20   2012-09-01 00:00:00.000
    DEP1       100ROC20   2012-10-01 00:00:00.000
    

    Essentially, the trick here is to build the Dates table on the fly and then cross-join that with Plant and Config. You could build the Dates table in a variety of other ways, such as with a tally table, cursor, while-loop, in asp.net itself, etc. I like the ease of a recursive CTE here, though I’m assuming a small number of dates need to be generated. More than 100 dates will require that maxrecursion be set, if not picking another method entirely if performance is a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables Plant config ------ -------- TRZ1 KS MAS1 MT I would
I have two tables table1 , table2 . Both have a one to one
I have created one table using the below command: create table Table1( Id int
I have two tables described below. What I need is a single query that
i have four tables like below in sql server 2008 : TABLE 1 ->
I have a problem. I have 3 tables like below: 1) met_ID (primair) etc.
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
I have three tables as shown in below image. Note: Lead column of projectheader
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
I have 3 tables with values like below **tbl_product** recID pID price colour 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.