UPDATE DateTime - how do I do it?

  • I'm trying to write a sql statement to update a row in a database table using UPDATE. I've tried different combinations of +," and ' but it's really confusing where to use what... I'm very thankul for any help on how to write this statement correctly! Below is a faulty statement. mID is int, Start & End are DateTime.

    "UPDATE Meeting SET mID" = + mID + ", Start=" + Start + ", End=" + End + " WHERE ID = 'ID' ";

  • Why dynamic SQL?

    That's not the entire batch? Please post the entire thing.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • This is how I've learned to write sql-statements...

    Entire batch? I'm only wondering how to formulate the statement, or more specifically how to formulate the values that are to be set.

  • What client are you using to run the statement?

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • I'm beginning to think I'm in the wrong forum, maybe this isn't a place for any questions concerning how to use sql? I don't think it matters which programs or clients I use, I'm just trying to find an answer to how to use DateTime format in an sql update statement. If I'm in the wrong place then I'm sorry to have disturbed and I'll get out of here ๐Ÿ™‚

  • Where are the values coming from? They're not SQL variables (no @). They look like column references, but there's no table in scope.

    Take a couple steps back, give us the table structure and explain what you're trying to do here.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • karin.askeroth (8/9/2010)


    I'm beginning to think I'm in the wrong forum, maybe this isn't a place for any questions concerning how to use sql?

    Well it's the newbies forums, so I think this fits.

    We're asking questions because that statement makes no sense. It won't even parse like that, so either there's more to it than that or we're all not understanding what you're trying to do here.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I found help somewhere else, will se if I can mark as answered or delete post anywhere... Thanks for you time.

  • No need, there's no deleted or answered settings here. If you want, you could post the solution for anyone who runs across the thread from a search engine.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • karin.askeroth (8/9/2010)


    I'm beginning to think I'm in the wrong forum, maybe this isn't a place for any questions concerning how to use sql? I don't think it matters which programs or clients I use, I'm just trying to find an answer to how to use DateTime format in an sql update statement. If I'm in the wrong place then I'm sorry to have disturbed and I'll get out of here ๐Ÿ™‚

    Not at all, you're in the right place.

    This is generally how you would script your UPDATE in the SQL Server client tools e.g. SQL Server Management Studio:

    DECLARE @mID INT, @Start DATETIME, @End DATETIME, @ID INT

    SET @mID = ...

    SET @Start = ...

    SET @End = ...

    SET @ID = ...

    UPDATE Meeting SET

    mID = @mID,

    Start = @Start,

    End = @End

    WHERE ID = @ID

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 10 posts - 1 through 10 (of 10 total)

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