Solved

Problem with weekday in datepart

Posted on 2006-07-11
4
610 Views
Last Modified: 2008-02-01
Hi Experts,

In SQL Server 2000 I have the following query:

CREATE PROCEDURE dbo.xTestDatePart
AS SELECT     DATEPART(month, GETDATE()) AS 'Month Number', DATEPART(weekday, GETDATE()) AS Day
GO

Today is Tuesday. When I run this in QA on my server I get the results:
------------ -----------
7            2
@RETURN_VALUE = 0

and in my Access 2003 adp file running on my local machine connecting to the same db I get the results 7 3

On my server SELECT @@Datefirst returns 1 and in my adp file it returns 7

If anyone can advise where things are going wrong / what settings to examine in order to solve this problem I'd be grateful.

Thanks,

Louise
0
Comment
Question by:louise001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
DonKronos earned 125 total points
ID: 17081856
Change the procedure like this to get 7 3 returned by sql server

CREATE PROCEDURE dbo.xTestDatePart
AS
SET DATEFIRST 7
SELECT     DATEPART(month, GETDATE()) AS 'Month Number', DATEPART(weekday, GETDATE()) AS Day
GO

0
 

Author Comment

by:louise001
ID: 17082335
That works so thanks for that. I don't understand though why Access and SQL server return different answers when they're looking at the same db (local settings in each application?) - could you clarify this?
0
 
LVL 15

Expert Comment

by:DonKronos
ID: 17082657
You might want to look at this link.

http://msdn2.microsoft.com/en-US/library/ms187766.aspx

By default for U.S. English @@DATEFIRST is 7.  But it can be different for different languages, for example, for Italian @@DATEFIRST defaults to 1.

Also, @@DATEFIRST will reflect the most recent SET DATEFIRST in the session.  Thus, if you run a stored procedure that sets DATEFIRST prior to running your stored procedure you will get the value set by the previous stored procedure.

Also, the value of DATEFIRST is dependent on the settings withing the "language" (T-SQL or Access) and not the database itself.

Hope this helps.
0
 

Author Comment

by:louise001
ID: 17082745
That's helpful, thanks, will award points

Louise
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question