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 2008
»
T-SQL (SS2K8)
»
row_number replacement
row_number replacement
Rate Topic
Display Mode
Topic Options
Author
Message
komal145
komal145
Posted Wednesday, September 26, 2012 2:14 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 1:38 PM
Points: 168,
Visits: 540
Hi friends,
I have created temp table with row_number() since i need the latest loanumber with step
Create Table #Max_step
(
Loan_number varchar(10),
FID Int,
Step int,
Modifieddate datetime,
ROW_id int
)
Create table Tableb
(loan_number varchar(10),
step int,
Description varchar(20))
Insert into #Max_step values('91746',1110,2,'2010-07-31 19:34:35.000',2)
Insert into #Max_step values('91746',1120,1,'2010-07-31 19:30:35.000',3)
Insert into #Max_step values('91746',1120,3,'2010-07-31 19:30:35.000',1)
Insert into Tableb values('91746',1,'description1')
Insert into Tableb values('91746',2,'description2')
I am trying to update a column in TableB based on the row_id =2 from max_step
but every time i check the target column value changes ..example
updating Column in tableC where max_step.row_id=2 joined with tableB on step and loanumber.
UPDATE TableC
SET step_desc= Tableb.StepDescription
FROM #MAX_STEP MAX_STEP WITH (NOLOCK)
JOIN Tableb B WITH (NOLOCK) ON MAX_STEP.LoanNumber = b.LoanNumber
and MAx_step.Step=b.step
WHERE MAX_STEP.Row_ID = 2
Can Anyone tell me whats the best way to replace row_number() while getting data into max_step table
Post #1364924
Sean Lange
Sean Lange
Posted Wednesday, September 26, 2012 3:46 PM
SSCrazy Eights
Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 8,547,
Visits: 8,204
Can you ddl and sample data for TableC? Also, a clear explanation what you are trying would help. I am not sure I understand your requirements.
_______________________________________________________________
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 #1364959
brendan woulfe
brendan woulfe
Posted Thursday, September 27, 2012 7:12 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 9:05 AM
Points: 192,
Visits: 910
I don't see what's wrong with your query other than you don't have a loannumber column. It is loan_number.
Post the ddl and sample data for TableC and give expected output and someone should be able to help.
Post #1365225
ChrisM@Work
ChrisM@Work
Posted Thursday, September 27, 2012 7:29 AM
SSCertifiable
Group: General Forum Members
Last Login: 2 days ago @ 8:21 AM
Points: 5,602,
Visits: 10,950
komal145 (9/26/2012)
...
UPDATE TableC
SET step_desc= Tableb.StepDescription
FROM #MAX_STEP MAX_STEP WITH (NOLOCK)
JOIN Tableb B WITH (NOLOCK) ON MAX_STEP.LoanNumber = b.LoanNumber
and MAx_step.Step=b.step
WHERE MAX_STEP.Row_ID = 2...
This is an
unrestricted update
. Every row in tableC will be updated to the same value of step_desc, because TableC isn't referenced in the FROM list. Since it's a trivial matter to convert a SELECT...FROM into an UPDATE...FROM, why don't you write it and post it here? What you want is a query which will return step_desc from TableC and Tableb.StepDescription.
“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
Exploring Recursive CTEs by Example
Dwain Camps
Post #1365249
« 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.