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 7590513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:25:12+00:00 2026-05-30T20:25:12+00:00

I have a table like this : (note that id_pack is not auto incremented)

  • 0

I have a table like this : (note that id_pack is not auto incremented)

id_pack       start_date         end_date           is_parent   id_contract
1             2011-11-01         2012-01-18         1           5547
2             2012-01-18         2050-01-01         1           5547
3             2009-02-02         2050-01-01         0           5547

where id_pack = 3 is the child of the two parents. I want to make a query to select the parents and the child for the month 2012-01 but the child needs to be doubled (because his first parent finished on 2012-01-18). So the result needs to look like this :

id_pack       start_date         end_date         id_parent
1             2012-01-01         2012-01-18       0
2             2012-01-18         2012-01-31       0
3             2012-01-01         2012-01-18       1
3             2012-01-18         2012-01-31       2

I have tried in every way and I can’t figure it out. I’m doing this because parents are assigned a price rate in another table, and for the current month the child had two parents with different price rates, so I need to charge from 2012-01-01 : 2012-01-18 using a rate plan and from 2012-01-18 : 2012-01-31 using another rate plan.

Is this even possible with one query ?

Thank you

PS: I have something like this :

    select c.id_pack,
            case when c.start_date < '2012-01-01' then '2012-01-01'
            else c.start_date
            end as start_date, 

            case end date ...... the same as start_date as end_date,


    from client a 
    join contract b on b.id_client = a.id_client
    join package c on c.id_contract = b.id_contract
       and c.start_date < dateadd(mm,1,'2012-01-01')
       and c.end_date >= '2012-01-01'
    where a.id_clinet = '12345'
  • 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-05-30T20:25:13+00:00Added an answer on May 30, 2026 at 8:25 pm

    Try:

    select c.id_pack, p.start_date, p.end_date, coalesce(p.id_pack,0) id_parent
    from package c
    left join package p 
           on c.contract_id = p.contract_id and p.is_parent = 1 and c.is_parent = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML Table that looks like this: The user can update any
for SQL Server 2008 R2 I have a resultset that looks like this (note
I have a mySQL table that has a column like this: ID ----- 0352
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a table like this: <table> <tfoot> <tr><td>footer</td></tr> </tfoot> <tbody> <tr><td>Body 1</td></tr> <tr><td>Body
I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- |
I have a table like this: name code group john 12 smith 15 how
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName

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.