|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 1,162,
Visits: 3,333
|
|
Below I've setup a practical illustration of why this matters. Using the exact same SQL query, the sum of payments is 100.00 when LANGUAGE is set to US_ENGLISH, but the sum is 300.00 for ITALIAN and FRENCH. Thanks, Lynn, for pointing out that YYYYMMDD (not YYYY-MM-DD) is the correct format to use for LANGUAGE and DATEFORMAT setting independence. We have to remember that the application or client tool can apply these settings at the connection level, so it would be best to always use YYYYMMDD format in our SQL queries.
create table #customer_payment ( primary key( customer_id, payment_date), customer_id int not null, payment_date datetime not null, payment_amt smallmoney not null ); insert into #customer_payment ( customer_id, payment_date, payment_amt ) values ( 123, '20120112', 100.00 ), ( 123, '20120505', 100.00 ), ( 123, '20121207', 100.00 ); Then, run the following query under each language:
select sum(payment_amt)payment_amt from #customer_payment where customer_id = 123 and payment_date >= '2012-10-01';
SET LANGUAGE US_ENGLISH; Changed language setting to us_english. payment_amt --------------------- 100.00
SET LANGUAGE ITALIAN; L'impostazione della lingua è stata sostituita con Italiano. payment_amt --------------------- 300.00
Le paramètre de langue est passé à Français. SET LANGUAGE FRENCH; payment_amt --------------------- 300.00 However, modifying the search condition to YYYYMMDD format like below, the query returns 100.00 under all three languages.
select sum(payment_amt)payment_amt from #customer_payment where customer_id = 123 and payment_date >= '20121001';
"Wise people understand the 10,000 things without going to each one. They know them without having to look at each one, and they transform all without acting on each one." - The Tao Te Ching: Verse 47
|
|
|
|