Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Sequence Expand / Collapse
Author
Message
Posted Wednesday, December 22, 2010 8:28 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 4:53 AM
Points: 1,159, Visits: 1,545
da-zero (12/22/2010)
paul.goldstraw (12/22/2010)
I got it right based on the fact that an update statement shouldn't ever be able to change the number of records in a table - since 8 rows were inserted the only possible answer was the first one (assuming there was no error). I got it right but was I correct in making that assumption or did I just get lucky? I can't think of any circumstance where an update would do that but have I missed something?

Paul


Unless you implement the update as an delete and an insert and something goes horribly wrong in between, I would be very surprised


That's what I thought :) Thanks for the confirmation

Paul
Post #1038300
Posted Wednesday, December 22, 2010 4:16 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 3:20 PM
Points: 18,064, Visits: 16,099
Thanks for the question



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1038547
Posted Friday, December 24, 2010 6:25 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 2:31 PM
Points: 227, Visits: 353
Thank you all for your comments. LIttle history behind why i came up with this querey. I work as a sql dba and report writer for a legal collections agency. we have tables were there are multiple rows for each account something to the nature of the below example

accoount field
1234 12345678
1234 90123456
1234 78901234

the field value is phone numbers or other data that was given to us by clients. what i was tasked to do was get all those numbers in one row

1234 12345678 90123456 78901234

using this statement i am able to get all instances of a sepcific account and line up the varios numbers given to us by clients. i am going to try the suggestions i have seen here to change the query for more effeciency. what i am doing is loading the different instances of accounts into temp tables updating the sequence so that i can join in my final report. i am out of the office until tuesday but once back in office i will post my final query that i use for my report and possibly that will shed more light as to my madness :)

Again thank you all for comments.
Post #1039178
Posted Tuesday, December 28, 2010 10:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
Thanks for the question.
Post #1039888
Posted Tuesday, December 28, 2010 1:03 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: 2 days ago @ 4:18 PM
Points: 9,928, Visits: 11,206
Oleg Netchaev (12/21/2010)
For example, the update in question can be easily restated like this:

Or, even more succinctly:

WITH    Records (Old_Seq, New_Seq)
AS (
SELECT Seq,
ROW_NUMBER() OVER (PARTITION BY Value ORDER BY RecID)
FROM #Test
)
UPDATE Records
SET Old_Seq = New_Seq;

Paul




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1039964
Posted Tuesday, December 28, 2010 1:35 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, November 24, 2014 8:33 AM
Points: 1,676, Visits: 1,760
SQLkiwi (12/28/2010)
Or, even more succinctly:

WITH    Records (Old_Seq, New_Seq)
AS (
SELECT Seq,
ROW_NUMBER() OVER (PARTITION BY Value ORDER BY RecID)
FROM #Test
)
UPDATE Records
SET Old_Seq = New_Seq;

Paul

This is really elegant, thank you so much Paul! Since there is no way to use the windowing functions directly in the set, I thought that update from join is a necessary evil to workaround the issue. I am glad that it is not.

Oleg
Post #1039980
Posted Friday, April 29, 2011 9:59 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Sunday, March 4, 2012 4:02 AM
Points: 660, Visits: 134
get all those numbers in one row


Now I understand what you were trying to achieve. Thanks for the question.
Post #1100929
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse