Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with weekday in datepart

Posted on 2006-07-11
4
Medium Priority
?
615 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
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
DonKronos earned 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

885 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