Changing setting for first day of the week

  • Hi there,

    I am having some trouble with some SQL Job schedules because I believe SQL is using Sunday as the first day of the week by default. I have separate jobs for each weekend which must run Friday, Saturday, Sunday consecutively. Unfortunately, as SQL considers Sunday the first day of the week, they are running first on the Sunday and then the following Friday and Saturday. Is there a way to change the setting for the first day of the week?

    So, effectively I would be looking to go from this:

    1 - Sunday

    2 - Monday

    3 - Tuesday

    4 - Wednesday

    5 - Thursday

    6 - Friday

    7 - Saturday

    ...to this...

    1 - Monday

    2 - Tuesday

    3 - Wednesday

    4 - Thursday

    5 - Friday

    6 - Saturday

    7 - Sunday

    Any ideas? I'm also not sure if changing this could affect anything else other than for SQL Jobs?

    Thanks

  • Did you try:

    SET DATEFIRST 1;

    GO

    Check the first date with

    SELECT @@DATEFIRST

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Also I don't know which language you are using, however you can change the language for the user like:

    Check the language that has the first date Monday... more correct check the value of the DateFirs col, that is third col in your results. is it 1!

    SELECT * FROM sys.syslanguages

    Then, now try to change the language of the user that you've created to run schedule jobs, like this:

    USE [master]

    GO

    ALTER LOGIN WITH DEFAULT_LANGUAGE = "Your language that you have choose to be from syslanguages"

    GO

    Sample:

    USE [master]

    GO

    ALTER LOGIN [YourUserName] WITH DEFAULT_LANGUAGE = [Deutsch]

    GO

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Thanks Dugi - that looks good!

    Currently the jobs just run under the domain account that runs the SQL Agent Services, although this account is not listed under the Logins in SSMS. There is a login called 'NT SERVICE\SQLSERVERAGENT' though - is this what needs changing? Or do I need to add the domain service account to the logins and set the language for that?

  • those set options are connection specific; they are not server wide.

    just because you set it someplace, does not mean it's going to affect jobs or anything else on the server.

    each job would need to be edited to have new set options.

    if you are connecting with , say .NET, you need to set the options there.

    SSMS has a place where you can change most of those settings via the GUI , and every ODBC driver has the ability to set them as well.

    Note that even if you could set these items server wide, they would be over-riden by the connections settings themselves.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Hi Lowell,

    These are just standard SQL Agent Jobs being run on a schedule, so I'm assuming I could just change the default language setting for the login they are being run under (currently the SQL Agent Service account)?

    Would changing the default language for 'NT SERVICE\SQLSERVERAGENT' do this?

    Thanks

  • matt.gyton (10/22/2012)


    Hi Lowell,

    These are just standard SQL Agent Jobs being run on a schedule, so I'm assuming I could just change the default language setting for the login they are being run under (currently the SQL Agent Service account)?

    Would changing the default language for 'NT SERVICE\SQLSERVERAGENT' do this?

    Thanks

    i think so yes, but you'd have to test it. it would be better to change whatever script you are using to not be sensuitive to datefirst instead;

    can you explain what is not running or occuring correctly because of that setting?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (10/22/2012)


    matt.gyton (10/22/2012)


    Hi Lowell,

    These are just standard SQL Agent Jobs being run on a schedule, so I'm assuming I could just change the default language setting for the login they are being run under (currently the SQL Agent Service account)?

    Would changing the default language for 'NT SERVICE\SQLSERVERAGENT' do this?

    Thanks

    i think so yes, but you'd have to test it. it would be better to change whatever script you are using to not be sensuitive to datefirst instead;

    can you explain what is not running or occuring correctly because of that setting?

    Basically each Job runs a windows CmdExec command, which kicks off a Netbackup procedure. There are 4 jobs, Weekly1, Weekly2, Weekly3 and Monthly. Each weekend, one of these jobs must be run consecutively on the Friday, Saturday and Sunday as follows:

    Week 1: Weekly1 runs Friday, Saturday and Sunday.

    Week 2: Weekly2 runs Friday, Saturday and Sunday.

    Week 3: Weekly3 runs Friday, Saturday and Sunday.

    Week 4: Monthly runs Friday, Saturday and Sunday.

    The problem is that because SQL considers Sunday the first day of the week, the Friday and Saturday are considered to be part of one week, but the Sunday is part of the next week, so instead of running on consecutive days they run as follows:

    Week 1: Weekly1 runs Sunday......Friday, Saturday.

    Week 2: Weekly2 runs Sunday......Friday, Saturday.

    Week 3: Weekly3 runs Sunday......Friday, Saturday.

    Week 4: Monthly runs Sunday......Friday, Saturday.

    Hope that makes sense!!

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply