Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
How to write Update query for this scenario
How to write Update query for this scenario
Rate Topic
Display Mode
Topic Options
Author
Message
kak.mca
kak.mca
Posted Thursday, November 08, 2012 2:33 AM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, December 18, 2012 1:37 AM
Points: 5,
Visits: 15
RowId EName Project Time part Hours
Worked [14 Jan] [15 Jan] [16 Jan]
1 Emp 1 Project 1 14/1/2010 7.0
2 Emp 2 Project 2 15/1/2010 8.0
3 Emp 1 Project 1 16/1/2010 8.0
From the above table:
The above table is showing like
Emp 1 has worked for 7.0 hours on Project 1 on 14/1/2010.
Emp 2 has worked for 8.0 hours on Project 2 on 15/1/2010.
Emp 1 has worked for 8.0 hours on Project 1 on 16/1/2010.
I want to update the above table like below:
I want to update the column [14 Jan] column first row with 7.0 for Emp 1
I want to update the column [15 Jan] column second row with 8.0 for Emp 2
I want to update the column [16 Jan] column third row with 8.0 for Emp 1
Hence the result should be:
RowId EName Project Time part Hours
Worked [14 Jan] [15 Jan] [16 Jan]
1 Emp 1 Project 1 14/1/2010 7.0 7.0
2 Emp 2 Project 2 15/1/2010 8.0 8.0
3 Emp 1 Project 1 16/1/2010 8.0 8.0
Can anybody please suggest me how to write the query for the same in SQL Server 2005?
Post #1382344
Sean Lange
Sean Lange
Posted Thursday, November 08, 2012 7:50 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 10:09 AM
Points: 8,632,
Visits: 8,269
kak.mca (11/8/2012)
RowId EName Project Time part Hours
Worked [14 Jan] [15 Jan] [16 Jan]
1 Emp 1 Project 1 14/1/2010 7.0
2 Emp 2 Project 2 15/1/2010 8.0
3 Emp 1 Project 1 16/1/2010 8.0
From the above table:
The above table is showing like
Emp 1 has worked for 7.0 hours on Project 1 on 14/1/2010.
Emp 2 has worked for 8.0 hours on Project 2 on 15/1/2010.
Emp 1 has worked for 8.0 hours on Project 1 on 16/1/2010.
I want to update the above table like below:
I want to update the column [14 Jan] column first row with 7.0 for Emp 1
I want to update the column [15 Jan] column second row with 8.0 for Emp 2
I want to update the column [16 Jan] column third row with 8.0 for Emp 1
Hence the result should be:
RowId EName Project Time part Hours
Worked [14 Jan] [15 Jan] [16 Jan]
1 Emp 1 Project 1 14/1/2010 7.0 7.0
2 Emp 2 Project 2 15/1/2010 8.0 8.0
3 Emp 1 Project 1 16/1/2010 8.0 8.0
Can anybody please suggest me how to write the query for the same in SQL Server 2005?
From what you posted it is nearly impossible to determine what you are trying to do or how to write the code. We would need ddl (create table statements), sample data (insert statements) and desired output based on the sample data. Take a look at the first link in my signature for best practices when posting questions.
_______________________________________________________________
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 Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1382505
Luis Cazares
Luis Cazares
Posted Thursday, November 08, 2012 8:02 AM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 3:57 PM
Points: 960,
Visits: 1,923
I can help you to write the update statement. But I would like to know why are you doing this? This will help you with 3 days but what happens with a whole month? or a whole year? Why do you have this table design?
You shouldn't store values that way, to show the results in a report would be ok (even if some people say it should be done in the front end).
Please, review the requirements and then confirm you need to do this.
Luis C.
Please don't trust me, test the solutions I give you before using them.
Forum Etiquette: How to post data/code on a forum to get the best help
Post #1382512
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.