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
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 8:19 AM
Points: 940, Visits: 1,281
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


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 9:30 PM
Points: 20,467, Visits: 14,104
Thanks for the question



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
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, April 09, 2014 7:56 AM
Points: 221, Visits: 306
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: Thursday, March 27, 2014 8:50 AM
Points: 2,163, Visits: 2,184
Thanks for the question.
Post #1039888
Posted Tuesday, December 28, 2010 1:03 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 10:03 PM
Points: 11,168, Visits: 10,934
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: Tuesday, April 01, 2014 2:53 PM
Points: 1,676, Visits: 1,744
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 04, 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