How to get localized name of NSBundle* - objective-c

I try to get the localized name of an app on MacOS.
static void printBundleInfo(NSBundle *bundle)
{
auto printNSString = [](NSString *s){ INFO << QString::fromNSString(s); };
INFO << "------ BundleInfo ------";
printNSString(bundle.bundlePath);
//printNSString(bundle.bundleURL);
printNSString(bundle.bundleIdentifier);
printNSString([bundle objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey]);
printNSString([bundle objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]);
// printNSString([bundle objectForInfoDictionaryKey:(NSString*)kCFBundleLocalizationsKey]);
printNSString([bundle.localizedInfoDictionary objectForKey:(NSString*)kCFBundleNameKey]);
printNSString(bundle.localizedInfoDictionary[#"CFBundleDisplayName"]);
//NSString *language = bundle.preferredLocalizations.firstObject;
//printNSString(language);
NSString *countryCode = [NSLocale.currentLocale objectForKey:NSLocaleCountryCode];
printNSString(countryCode);
NSString *preferred_language = NSLocale.preferredLanguages[0];
printNSString(preferred_language);
// NSString *local_ns_name = [bundle objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
// printNSString(local_ns_name);
DEBG << "bundle.localizations";
for (NSString *nss in bundle.localizations)
printNSString(nss);
}
If i run this for the clock.app i get
23:20:33 [info:applications] ------ BundleInfo ------
23:20:33 [info:applications] /System/Applications/Clock.app
23:20:33 [info:applications] com.apple.clock
23:20:33 [info:applications] Clock
23:20:33 [info:applications] 62
23:20:33 [info:applications] Clock
23:20:33 [info:applications] Clock
23:20:33 [info:applications] DE
23:20:33 [info:applications] de
23:20:33 [debg:applications] bundle.localizations
23:20:33 [info:applications] de
23:20:33 [info:applications] he
23:20:33 [info:applications] en_AU
23:20:33 [info:applications] ar
23:20:33 [info:applications] el
23:20:33 [info:applications] ja
23:20:33 [info:applications] en
23:20:33 [info:applications] uk
23:20:33 [info:applications] es_419
23:20:33 [info:applications] zh_CN
23:20:33 [info:applications] es
23:20:33 [info:applications] da
23:20:33 [info:applications] it
23:20:33 [info:applications] sk
23:20:33 [info:applications] pt_PT
23:20:33 [info:applications] ms
23:20:33 [info:applications] sv
23:20:33 [info:applications] cs
23:20:33 [info:applications] ko
23:20:33 [info:applications] no
23:20:33 [info:applications] hu
23:20:33 [info:applications] zh_HK
23:20:33 [info:applications] tr
23:20:33 [info:applications] pl
23:20:33 [info:applications] zh_TW
23:20:33 [info:applications] en_GB
23:20:33 [info:applications] vi
23:20:33 [info:applications] ru
23:20:33 [info:applications] fr_CA
23:20:33 [info:applications] fr
23:20:33 [info:applications] fi
23:20:33 [info:applications] id
23:20:33 [info:applications] nl
23:20:33 [info:applications] th
23:20:33 [info:applications] pt
23:20:33 [info:applications] ro
23:20:33 [info:applications] hr
23:20:33 [info:applications] hi
23:20:33 [info:applications] ca
Obviously something is wrong. Preferred localization is de, but localizedInfoDictionary returns the english version. Launchpad shows the german localization Uhr.app. How can I get a localized name?

Related

SQL Server Get Last 3 Months of Date Using Year and Month Columns?

select
d.TransfCompPeriod,
d.TransfCompYear,
a.GtrReference,
a.SourceWarehouse,
max(a.TargetWarehouse) over (partition by a.GtrReference) as TargetWarehouse, a.DateCreated,
COALESCE(d.ExpectedDueDate, d.ExpectedDueDate) as ExpectedDueDate,
a.EntryType,
a.ControlAccount,
max(a.InitialValue) over (partition by a.GtrReference) as InitialValue,
a.Operator,
b.Description,
c.Description
FROM
[GtrMaster] a
LEFT JOIN [InvWhControl] b
ON (a.SourceWarehouse = b.Warehouse)
LEFT JOIN [InvWhControl] c
ON (a.TargetWarehouse = c.Warehouse)
LEFT JOIN [GtrDetail] d
ON (a.GtrReference = d.GtrReference)
WHERE ( a.EntryType = 'W' OR a.EntryType = 'S' )
AND a.Complete = 'Y' AND a.GtrReference >= ''
and d.Line = '1'
ORDER BY a.GtrReference
I have a query that generates this table:
TransfCompPeriod
TransfCompYear
GtrReference
SourceWarehouse
TargetWarehouse
DateCreated
ExpectedDueDate
EntryType
ControlAccount
InitialValue
Operator
Description
Description
8
2021
000360
W
01
2021-08-11 00:00:00.000
2021-08-18 00:00:00.000
W
1610
792.88
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2019
01/19
W
01
2019-02-01 00:00:00.000
2019-02-04 00:00:00.000
W
1610
18159.77
AWAINWRIGHT
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2023
01062023
W
01
2023-01-06 00:00:00.000
2023-02-21 00:00:00.000
W
1610
6080.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2023
01172023
W
01
2023-01-17 00:00:00.000
2023-01-31 00:00:00.000
W
1610
6210.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2020
01232020-NYTOAK
01
02
2020-01-23 00:00:00.000
2020-01-24 00:00:00.000
W
1610
16412.35
CWHITE
MAIN WAREHOUSE
Akron Facility- Finished Goods
2
2021
01272021
W
01
2021-01-27 00:00:00.000
2021-02-05 00:00:00.000
W
1610
437.36
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2021
02112021
W
01
2021-02-11 00:00:00.000
2021-02-19 00:00:00.000
W
1610
10140.95
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2022
02112022
W
01
2022-02-11 00:00:00.000
2022-02-28 00:00:00.000
W
1610
960.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
3
2021
02232021
W
01
2021-02-23 00:00:00.000
2021-03-01 00:00:00.000
W
1610
2368.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
3
2022
02232022
W
01
2022-02-23 00:00:00.000
2022-03-04 00:00:00.000
W
1610
7443.20
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
WHat I'm trying to do is filter in an AND statement that TransfCompPeriod and TransfCompYear will only pull for the last 3 months, but I'm not sure how to do it with those two columns. Can someone help me put together the right sql for that in my AND statement?
So for example, I want to see the BELOW (today being 02 / 08 /2023 and only showing the last 3 months)
TransfCompPeriod
TransfCompYear
GtrReference
SourceWarehouse
TargetWarehouse
DateCreated
ExpectedDueDate
EntryType
ControlAccount
InitialValue
Operator
Description
Description
2
2023
01062023
W
01
2023-01-06 00:00:00.000
2023-02-21 00:00:00.000
W
1610
6080.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2023
01172023
W
01
2023-01-17 00:00:00.000
2023-01-31 00:00:00.000
W
1610
6210.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
10282022
W
01
2022-10-28 00:00:00.000
2022-11-04 00:00:00.000
W
1610
162.14
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2023
202209-020
W
01
2022-09-16 00:00:00.000
2022-09-23 00:00:00.000
W
1610
4512.00
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
202210-036
W
01
2022-10-27 00:00:00.000
2022-12-30 00:00:00.000
W
1610
24643.20
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
202301-005
W
01
2023-01-03 00:00:00.000
2023-01-10 00:00:00.000
W
1610
1562.50
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
22111796
W
01
2022-11-28 00:00:00.000
2023-01-09 00:00:00.000
W
1610
22090.88
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
22120969
W
01
2022-12-22 00:00:00.000
2022-12-27 00:00:00.000
W
1610
23844.89
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
22120981
W
01
2022-12-14 00:00:00.000
2023-01-25 00:00:00.000
W
1610
41430.27
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010001
W
01
2023-01-03 00:00:00.000
2023-01-09 00:00:00.000
W
1610
6.27
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010005
W
DS
2023-01-03 00:00:00.000
2023-01-11 00:00:00.000
W
1610
34648.83
ahsiao
IN TRANSIT WAREHOUSE
DROP SHIPMENT
1
2023
23010306
W
01
2023-01-06 00:00:00.000
2023-01-13 00:00:00.000
W
1610
105.18
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010408
W
01
2023-01-09 00:00:00.000
2023-01-16 00:00:00.000
W
1610
94.49
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010629
W
01
2023-01-11 00:00:00.000
2023-01-20 00:00:00.000
W
1610
37607.70
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010629-01
W
01
2023-01-11 00:00:00.000
2023-01-20 00:00:00.000
W
1610
2400.30
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010629-1
W
01
2023-01-11 00:00:00.000
2023-01-20 00:00:00.000
W
1610
69.65
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
23010630
W
DS
2023-01-11 00:00:00.000
2023-01-18 00:00:00.000
W
1610
8560.26
ahsiao
IN TRANSIT WAREHOUSE
DROP SHIPMENT
1
2023
23011427
W
01
2023-01-23 00:00:00.000
2023-01-30 00:00:00.000
W
1610
238.18
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
2
2023
23011634
W
01
2023-01-25 00:00:00.000
2023-02-03 00:00:00.000
W
1610
27559.02
ahsiao
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE
1
2023
7740
W
01
2022-12-30 00:00:00.000
2022-12-27 00:00:00.000
W
1610
348.00
CWHITE
IN TRANSIT WAREHOUSE
MAIN WAREHOUSE

Changing a pandas dataframe format into another format?

The given dataframe looks like this:
sensorA sensorB deviceA deviceB inputA inputB machineA machineB flagA flagB mainA
Time
2021-11-26 20:20:00 379.0 0.0 0.0 489.0 0.77 35.0 0.0 51.0 -13.0 230.0 1.6
2021-11-26 20:30:00 344.0 0.0 0.0 143.0 0.76 31.0 0.0 50.0 -11.0 230.0 1.8
I want to map this to a the following format separting the individual columns into a combination of Field and attribute.
Time
Type
attribute
Value
2021-11-26 20:20:00
sensor
a
999
I have tried mutiple directions to approch this using multi indexing, groupby etc but cant seem to get around on how to exactly impliment this ?
Any help would be appreciated!!
Edit
If your column names contain '_' as separator, you can use:
df.columns = df.columns.str.split('_', expand=True).rename(['Type', 'Tag'])
out = df.unstack().rename('Value').reset_index(level=['Type', 'Tag']).sort_index()
Extract type/tag from column names with a regular expression:
types = ['sensor', 'device', 'input', 'machine', 'flag', 'main']
pat = fr"({'|'.join(types)})(.*)"
df.columns = pd.MultiIndex.from_frame(df.columns.str.extract(pat),
names=['Type', 'Tag'])
out = df.unstack().rename('Value').reset_index(level=['Type', 'Tag']).sort_index()
Output:
>>> out
Type Tag Value
Time
2021-11-26 20:20:00 sensor A 379.00
2021-11-26 20:20:00 flag B 230.00
2021-11-26 20:20:00 flag A -13.00
2021-11-26 20:20:00 machine B 51.00
2021-11-26 20:20:00 machine A 0.00
2021-11-26 20:20:00 main A 1.60
2021-11-26 20:20:00 input A 0.77
2021-11-26 20:20:00 input B 35.00
2021-11-26 20:20:00 device B 489.00
2021-11-26 20:20:00 device A 0.00
2021-11-26 20:20:00 sensor B 0.00
2021-11-26 20:30:00 input A 0.76
2021-11-26 20:30:00 device A 0.00
2021-11-26 20:30:00 input B 31.00
2021-11-26 20:30:00 machine A 0.00
2021-11-26 20:30:00 sensor B 0.00
2021-11-26 20:30:00 machine B 50.00
2021-11-26 20:30:00 flag A -11.00
2021-11-26 20:30:00 sensor A 344.00
2021-11-26 20:30:00 flag B 230.00
2021-11-26 20:30:00 device B 143.00
2021-11-26 20:30:00 main A 1.80

Why my calculation does not match metatrader 4 backtest loss?

I am writing and expert advisor and ran a test. And I cannot understand, and find info why loss amount is not matching my calculations. To do backtesting I should get correct results.
So in the image we see there was 0.79 lot position opened at 109.87 closed at 109.939.
Here is the position size calculator showing swap.
But when backtesting I am getting even lower swap. Maybe calculator indicator is showing wrong. With lower swap the gap between expected loss and actual loss is even bigger.
So daily swap eats 6.15 usd. Account is in usd. From jan 22 to feb 6 it has been 17 swaps. Commision as you will see below in log is 3.16.
So my math is 6.15*17+52.5+3.16=160.21
but position loss is 175.48.
I also have printed swap each day:
2020.11.30 20:55:10.728 2020.02.06 00:00:00 adx USDJPY,H1: swap: -98.7114401
2020.11.30 20:55:10.728 2020.02.05 00:00:00 adx USDJPY,H1: swap: -81.29177420000001
2020.11.30 20:55:10.727 2020.02.04 00:00:00 adx USDJPY,H1: swap: -75.48521890000001
2020.11.30 20:55:10.727 2020.02.03 00:00:00 adx USDJPY,H1: swap: -69.67866360000001
2020.11.30 20:55:10.727 2020.01.31 00:00:00 adx USDJPY,H1: swap: -63.87210830000001
2020.11.30 20:55:10.721 2020.01.30 00:00:00 adx USDJPY,H1: swap: -58.06555300000001
2020.11.30 20:55:10.721 2020.01.29 00:00:00 adx USDJPY,H1: swap: -40.6458871
2020.11.30 20:55:10.721 2020.01.28 00:00:00 adx USDJPY,H1: swap: -34.8393318
2020.11.30 20:55:10.720 2020.01.27 00:00:00 adx USDJPY,H1: swap: -29.0327765
2020.11.30 20:55:10.720 2020.01.24 00:00:00 adx USDJPY,H1: swap: -23.2262212
2020.11.30 20:55:10.720 2020.01.23 00:00:00 adx USDJPY,H1: swap: -17.41966590000001
2020.11.30 20:55:10.719 2020.01.22 00:00:00 adx USDJPY,H1: commission -3.16
and it shows about 5.8 for one day. Which would make even bigger gap if I would use it for my calculation.

SQL Get distinct tax rate form a tax table

I am optimistic that some clever SQL author can tweak my query to give the results I am looking for. I have to extract the current tax rates for a state and distinct tax type (PST/QST/GST/HST) There is usually PST/GST or HST per state. Looking at the data table below I need to get the tax 'rate' for the distinct value of 'Shortname', 'name', and 'Effective Date'.
The desired result is this table:
EffectiveDate Rate ShortName name
2016-01-01 0.050000 AB GST
2013-04-01 0.050000 BC GST
2013-04-01 0.070000 BC PST
2013-07-01 0.050000 MB GST
2013-07-01 0.080000 MB PST
2016-07-01 0.150000 NB HST
2016-07-01 0.150000 NL HST
2016-01-01 0.150000 NS HST
2016-01-01 0.050000 NT GST
2016-01-01 0.050000 NU GST
2015-04-01 0.130000 ON HST
2016-10-01 0.150000 PE HST
2013-01-01 0.050000 QC GST
2017-03-01 0.099750 QC QST
2016-01-01 0.050000 SK GST
2017-03-01 0.060000 SK PST
2009-02-01 0.050000 YT GST
My query so far:
SELECT --TaxRates.ID, --TaxRates.StateId, TaxRateDetails.id,
TaxRateDetails.EffectiveDate, TaxRateDetails.Rate,--TaxRateDetails.TaxRateId,
States.ShortName, TaxImpositionTypes.name -- DISTINCT Name,states.ShortName, TaxRateDetails.Id,TaxImpositionTypeDetailId
FROM dbo.TaxRates
join dbo.TaxRateDetails ON TaxRateDetails.TaxRateId = TaxRates.Id
INNER JOIN States ON dbo.TaxRates.StateId = States.Id AND States.IsActive =1
INNER JOIN TaxImpositionTypeDetails ON TaxRateDetails.TaxImpositionTypeDetailId = TaxImpositionTypeDetails.Id
INNER JOIN TaxImpositionTypes ON dbo.TaxImpositionTypeDetails.TaxImpositionTypeId = TaxImpositionTypes.Id
WHERE EffectiveDate < CURRENT_TIMESTAMP
order BY ShortName
This source table created by this query is as follows:
EffectiveDate Rate ShortName name
2016-01-01 0.050000 AB GST
2009-02-01 0.050000 AB GST
2013-04-01 0.050000 BC GST
2013-04-01 0.070000 BC PST
2013-04-01 0.050000 BC GST
2013-04-01 0.070000 BC PST
2013-07-01 0.050000 MB GST
2013-07-01 0.080000 MB PST
2010-07-01 0.130000 NB HST
2016-07-01 0.150000 NB HST
2010-07-01 0.130000 NB HST
2009-02-01 13.000000 NL HST
2016-07-01 0.150000 NL HST
2010-07-01 0.130000 NL HST
2016-01-01 0.150000 NS HST
2010-07-01 0.150000 NS HST
2016-01-01 0.050000 NT GST
2009-02-01 0.050000 NT GST
2016-01-01 0.050000 NU GST
2009-02-01 0.050000 NU GST
2010-07-01 0.130000 ON HST
2009-02-01 0.050000 ON HST
2009-02-01 0.080000 ON PST
2010-03-01 0.130000 ON HST
2015-04-01 0.130000 ON HST
2015-04-01 0.000100 ON PST
2009-02-01 13.000000 PE HST
2013-04-01 0.140000 PE HST
2016-10-01 0.150000 PE HST
2013-01-01 0.050000 QC GST
2013-01-01 0.010000 QC QST
2012-01-01 0.050000 QC GST
2012-01-01 0.095000 QC QST
2017-03-01 0.099750 QC QST
2016-01-01 0.050000 SK GST
2016-01-01 0.050000 SK PST
2009-02-01 0.050000 SK GST
2009-02-01 0.050000 SK PST
2017-03-01 0.060000 SK PST
2009-02-01 0.050000 YT GST
If I understand the question correctly, we could assign a row number to each unique pairing of shortname and name order that pairing by effective date descending so the highest date is first. Then we only display row 1 of each unique pairing of shortname and name .
WITH CTE AS (
SELECT TaxRateDetails.EffectiveDate
, TaxRateDetails.Rate
, States.ShortName
, TaxImpositionTypes.name
, Row_number() over (partition by States.ShortName,TaxImpositionTypes.name ORDER BY TaxRateDetails.EffectiveDate DESC) RN
FROM dbo.TaxRates
INNER JOIN dbo.TaxRateDetails
ON TaxRateDetails.TaxRateId = TaxRates.Id
INNER JOIN States
ON dbo.TaxRates.StateId = States.Id
AND States.IsActive =1
INNER JOIN TaxImpositionTypeDetails
ON TaxRateDetails.TaxImpositionTypeDetailId = TaxImpositionTypeDetails.Id
INNER JOIN TaxImpositionTypes
ON dbo.TaxImpositionTypeDetails.TaxImpositionTypeId = TaxImpositionTypes.Id
WHERE EffectiveDate < CURRENT_TIMESTAMP)
SELECT * FROM CTE where RN = 1

Updating a SQL table with values from different rows in itself

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.
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'