August 9, 2010 at 3:47 am
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' ";
August 9, 2010 at 3:56 am
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
August 9, 2010 at 4:37 am
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.
August 9, 2010 at 4:43 am
What client are you using to run the statement?
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
August 9, 2010 at 4:54 am
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 ๐
August 9, 2010 at 4:55 am
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
August 9, 2010 at 5:02 am
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
August 9, 2010 at 5:03 am
I found help somewhere else, will se if I can mark as answered or delete post anywhere... Thanks for you time.
August 9, 2010 at 5:05 am
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
August 9, 2010 at 5:15 am
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
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