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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:07:06+00:00 2026-05-23T21:07:06+00:00

I have a table with 5 columns :- Country Code Language Warehouse ActiveFrom ActiveTo

  • 0

I have a table

with 5 columns :-

  • Country Code
  • Language
  • Warehouse
  • ActiveFrom
  • ActiveTo

A subset of data (apologies for the column headers being out of alignment:-

Country
Code
   Language 
      Warehouse
                    ActiveFrom          ActiveTo
AT  de  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
AT  de  WGN 2011-02-14 00:00:00.000 9999-12-31 23:59:59.000
BE  fr  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000
BE  fr  WGN 2011-02-14 00:00:00.000 9999-12-31 23:59:59.000
CH  de  WGN 2011-02-14 00:00:00.000 9999-12-31 23:59:59.000
CZ  sk  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
CZ  sk  WGN 2011-02-14 00:00:00.000 9999-12-31 23:59:59.000
DE  de  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000
DE  de  WGN 2011-02-14 00:00:00.000 9999-12-31 23:59:59.000

What I want to do, is update the ActiveTo column, to the value of the ActiveFrom Date (give or take a few milliseconds) for the same warehouse.

I’ve tried This :-

update Translations
 set ActiveTo = DateAdd(ms, -3, ot.ActiveFrom)
    from Translations ot
   Where Warehouse = 'WGN'
     and CountryCode = ot.CountryCode

but, it gives these results.

CountryCode Language    Warehouse   ActiveFrom  ActiveTo
AT  de  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
AT  de  WGN 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997
BE  fr  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000
BE  fr  WGN 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997
CH  de  WGN 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997
CZ  sk  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
CZ  sk  WGN 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997
DE  de  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000
DE  de  WGN 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997

It’s updating the right rows. But the value is wrong, it’s deducting 3 milliseconds from its own ActiveFrom Date, instead of the other warehouse start date.

This SQL gives the right results in a derived table:-

select t.CountryCode, t.Warehouse, DateAdd (ms, -3, ot.ActiveFrom) as 'TransferToBHU', t.ActiveFrom, t.ActiveTo,
   ot.CountryCode, ot.Warehouse, ot.ActiveFrom, ot.ActiveTo
from Translations t
inner join Translations ot
  on ot.CountryCode= t.CountryCode

Where t.Warehouse = ‘WGN’
and ot.Warehouse = ‘BHU’
Order by t.CountryCode

    CountryCode Warehouse   TransferToBHU   ActiveFrom  ActiveTo    CountryCode Warehouse   ActiveFrom  ActiveTo
AT  WGN 2011-08-07 23:59:59.997 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997 AT  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
BE  WGN 2011-08-31 23:59:59.997 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997 BE  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000
CZ  WGN 2011-08-07 23:59:59.997 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997 CZ  BHU 2011-08-08 00:00:00.000 9999-12-31 23:59:59.000
DE  WGN 2011-08-31 23:59:59.997 2011-02-14 00:00:00.000 2011-02-13 23:59:59.997 DE  BHU 2011-09-01 00:00:00.000 9999-12-31 23:59:59.000

Now, if I could get the calculated value in ‘TransferToBHU’ into the update value, that’s exactly what I want.

The simplest solution would update the ‘WGN’ warehouse values based on the ‘BHU’ values. However, the best would update based on getting the two latest ActiveFrom dates for a given CountryCode.

Either solution is acceptable, although if anyone supplies one that works on the dates – they will get the accepted answer.

Thanks in advance.

  • 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-23T21:07:06+00:00Added an answer on May 23, 2026 at 9:07 pm
    update t1
    set ActiveTo = DateAdd(ms, -3, t2.ActiveFrom)
    from Translations t1
       JOIN
       Translations t2 ON t1.CountryCode = t2.CountryCode
    Where t1.Warehouse = 'WGN' AND t2.Warehouse = 'BHU'
    

    Of course, country CH has no BHU row, so:

    update t1
    set ActiveTo = DateAdd(ms, -3, ISNULL(t2.ActiveFrom,t1.ActiveFrom))
    from Translations t1
       LEFT JOIN
       Translations t2 ON t1.CountryCode = t2.CountryCode
    Where t1.Warehouse = 'WGN' AND t2.Warehouse = 'BHU'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with 3 columns being country , user_id , gender .
I have a table with the following columns source_title, country, language, source_url I need
The table columns have the data type BLOB and CLOB. What are the corresponding
I have a table in my warehouse that has columns in all uppercase. It
I have a table with two columns: City Country I want a result set
I have a simple country table using a identity column for the primary key.
I have mysql table tmp with columns pid,city,state,country. I write queries so i can
I have a table with columns like this: | Country.Number | CountryName | |
I have table with 3 columns A B C. I want to select *
I have a table with columns ID, DateStamp and the ID need not be

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.