April 28, 2009 at 7:26 am
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
April 28, 2009 at 12:07 pm
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 30, 2009 at 4:05 am
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
April 30, 2009 at 7:15 am
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 4, 2009 at 12:38 am
Of course, that explains it... they have different language settings.
Thank you for your help.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply