Are the posted questions getting worse?

  • Alvin Ramard (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    CirquedeSQLeil (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    Yes, in SQL Server 2008 it is missing the data type. Should be:

    DECLARE @selectDate datetime = getdate() - 365;

    Agreed. As it is written in the article, you can do a getdate() - 365. Though there are different methods of achieving that.

    I think y'all missed the point I was trying to make. I was referring to:

    getdate() - 365 vs DATEADD(DAY, -365, GETDATE())

    Those are equivalent.

    I know they're equivalent, but I've always considered the first case to be bad practice.

    Oh. The thing that stuck out a lot for me was the actual declaration of the variable.

    I go back and forth between both methods - depending on mood.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I'm with Alvin. Wary of overloads on dates. Especially with potential calendar issues across time zones. I prefer using the functions that explicitly call for the operation

  • Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    CirquedeSQLeil (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    Yes, in SQL Server 2008 it is missing the data type. Should be:

    DECLARE @selectDate datetime = getdate() - 365;

    Agreed. As it is written in the article, you can do a getdate() - 365. Though there are different methods of achieving that.

    I think y'all missed the point I was trying to make. I was referring to:

    getdate() - 365 vs DATEADD(DAY, -365, GETDATE())

    Those are equivalent.

    I know they're equivalent, but I've always considered the first case to be bad practice.

    Now that I'll agree with!

    Thank you 😎



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Steve Jones - Editor (3/15/2010)


    I'm with Alvin. Wary of overloads on dates. Especially with potential calendar issues across time zones. I prefer using the functions that explicitly call for the operation

    I wary of a change in settings, or a version upgrade, causing this to fail.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Alvin Ramard (3/15/2010)


    CirquedeSQLeil (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    Yes, in SQL Server 2008 it is missing the data type. Should be:

    DECLARE @selectDate datetime = getdate() - 365;

    Agreed. As it is written in the article, you can do a getdate() - 365. Though there are different methods of achieving that.

    I think y'all missed the point I was trying to make. I was referring to:

    getdate() - 365 vs DATEADD(DAY, -365, GETDATE())

    What? They're both broken.

    Either one fails every four years.

    Edit: To be more precise, either one is wrong 1/4 of the time. Assuming it's meant to find the date one year ago.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Alvin Ramard (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    CirquedeSQLeil (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    Yes, in SQL Server 2008 it is missing the data type. Should be:

    DECLARE @selectDate datetime = getdate() - 365;

    Agreed. As it is written in the article, you can do a getdate() - 365. Though there are different methods of achieving that.

    I think y'all missed the point I was trying to make. I was referring to:

    getdate() - 365 vs DATEADD(DAY, -365, GETDATE())

    Those are equivalent.

    I know they're equivalent, but I've always considered the first case to be bad practice.

    Now that I'll agree with!

    Thank you 😎

    Well, I have learned something new.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    What I don't like about this is that it is attempting to subtract 1 year... and this will fail in leap years.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • GSquared (3/15/2010)


    Alvin Ramard (3/15/2010)


    CirquedeSQLeil (3/15/2010)


    Lynn Pettis (3/15/2010)


    Alvin Ramard (3/15/2010)


    Anybody else see a problem with this statement?

    DECLARE @selectDate = getdate()-365

    Yes, in SQL Server 2008 it is missing the data type. Should be:

    DECLARE @selectDate datetime = getdate() - 365;

    Agreed. As it is written in the article, you can do a getdate() - 365. Though there are different methods of achieving that.

    I think y'all missed the point I was trying to make. I was referring to:

    getdate() - 365 vs DATEADD(DAY, -365, GETDATE())

    What? They're both broken.

    Either one fails every four years.

    I have seen that one happen too. HAHAHA

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQL Server 2008

    declare @MyDate1 datetime,

    @MyDate2 datetime2;

    set @MyDate1 = getdate();

    set @MyDate2 = @MyDate1;

    select @MyDate1 - 10; -- Works

    select @MyDate2 - 10; -- Fails

    The error you get on the second one is like this one:

    Msg 206, Level 16, State 2, Line 3

    Operand type clash: datetime2 is incompatible with int

  • Lynn Pettis (3/15/2010)


    SQL Server 2008

    declare @MyDate1 datetime,

    @MyDate2 datetime2;

    set @MyDate1 = getdate();

    set @MyDate2 = @MyDate1;

    select @MyDate1 - 10; -- Works

    select @MyDate2 - 10; -- Fails

    The error you get on the second one is like this one:

    Msg 206, Level 16, State 2, Line 3

    Operand type clash: datetime2 is incompatible with int

    Thanks Lynn.

    Now Timewarp.......

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Timewarp may be broken. I tried to use it last night to rewind the weekend and I could not get it to work. 🙁



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Timewarp? Redo the weekend? I don't think so. The Air Force Academy Fighting Falcons Hockey Team worked hard to beat the Black Knights of Army! They are on their way to the AHA semi-finals. They play Sacred Heart this week. Go Air Force!

    😉

  • I'm fine with going back to Friday evening.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • You know ..... If the right "outsider" read the Thread, some of us might end up with free room and board for the rest of our lives, wall padding included. 😀 hmmm :w00t:



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Lynn only needs 4 more posts for 10,000 posts (not overall pts).

    CountDown on?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 15 posts - 12,661 through 12,675 (of 66,712 total)

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