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


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:44 AM
Points: 2,609, Visits: 6,463
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';




You are standing in an open field west of a white house, with a boarded front door.... Opening the small mailbox reveals a leaflet.

> read leaflet

"ZORK is a game of adventure, danger, and low cunning. In it you will explore some of the most amazing territory ever seen by mortals." http://www.web-adventures.org/cgi-bin/webfrotz?s=Zork1
Post #1421682
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse