Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Weird Question About Querying with Dates Expand / Collapse
Author
Message
Posted Tuesday, February 19, 2013 8:39 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:23 PM
Points: 1,792, Visits: 5,041
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';

Post #1421682
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse