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

SET DATEFIRST SQL Server Expand / Collapse
Author
Message
Posted Tuesday, April 28, 2009 7:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 16, 2014 6:28 AM
Points: 18, Visits: 87
Hi,

Is it possible to set datefirst for a database or server?
I have a week number function on two servers but one sql server returns an incorrect week number and the other one returns correct week number...

Has it something to do with the @@DATEFIRST setting; if so; how can I change that?
(Do not want to use SET DATEFIRST in my function.)

When I run SELECT @@DATEFIRST on the two servers I get 1 on the incorrect and 7 on the correct one.

Best regards,
nic
Post #705792
Posted Tuesday, April 28, 2009 12:07 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 13,282, Visits: 12,116
look up @@DATEFIRST on BOL.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #706147
Posted Thursday, April 30, 2009 4:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 16, 2014 6:28 AM
Points: 18, Visits: 87
Thanks for your answer but in BOL I don't see any info on how to change the DATEFIRST setting for the server. If I use SET DATEFIRST is will only affect the current session.

Is it possible to change this or do I have to build in some logic to correct this depending on what DATEFIRST returns?

Br,
nic
Post #707518
Posted Thursday, April 30, 2009 7:15 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 13,282, Visits: 12,116
It sounds like one of the servers language is something other than english and you are trying use @@Datefirst to return the first day consistently across all servers.

You will likely need to set the language in your script the gets this date.

try running this on the server with the "incorrect" result

select @@datefirst

set language english

select @@datefirst

This does not permanently change the language setting. It will remain with this setting for the current connection only. Any other connections will still use whatever language the server is setup to use.

Hope that helps.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #707656
Posted Monday, May 4, 2009 12:38 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 16, 2014 6:28 AM
Points: 18, Visits: 87
Of course, that explains it... they have different language settings.

Thank you for your help.
Post #709204
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse