﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by zulmanclock  / Sequence / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 08:52:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote] get all those numbers in one row [/quote]Now I understand what you were trying to achieve. Thanks for the question.</description><pubDate>Fri, 29 Apr 2011 09:59:12 GMT</pubDate><dc:creator>terrykzncs</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote][b]SQLkiwi (12/28/2010)[/b][hr]Or, even more succinctly:[code="sql"]WITH    Records (Old_Seq, New_Seq)AS      (        SELECT  Seq,                ROW_NUMBER() OVER (PARTITION BY Value ORDER BY RecID)        FROM    #Test        )UPDATE  RecordsSET     Old_Seq = New_Seq;[/code]Paul[/quote]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</description><pubDate>Tue, 28 Dec 2010 13:35:44 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote][b]Oleg Netchaev (12/21/2010)[/b][hr]For example, the update in question can be easily restated like this:[/quote]Or, even more succinctly:[code="sql"]WITH    Records (Old_Seq, New_Seq)AS      (        SELECT  Seq,                ROW_NUMBER() OVER (PARTITION BY Value ORDER BY RecID)        FROM    #Test        )UPDATE  RecordsSET     Old_Seq = New_Seq;[/code]Paul</description><pubDate>Tue, 28 Dec 2010 13:03:21 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Thanks for the question.</description><pubDate>Tue, 28 Dec 2010 10:52:23 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>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 exampleaccoount  field1234        123456781234        901234561234        78901234the 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 row1234  12345678 90123456 78901234using 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.</description><pubDate>Fri, 24 Dec 2010 18:25:58 GMT</pubDate><dc:creator>zulmanclock</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Thanks for the question</description><pubDate>Wed, 22 Dec 2010 16:16:51 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote][b]da-zero (12/22/2010)[/b][hr][quote][b]paul.goldstraw (12/22/2010)[/b][hr]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[/quote]Unless you implement the update as an delete and an insert and something goes horribly wrong in between, I would be very surprised :-)[/quote]That's what I thought :) Thanks for the confirmationPaul</description><pubDate>Wed, 22 Dec 2010 08:28:54 GMT</pubDate><dc:creator>paul.goldstraw</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote][b]paul.goldstraw (12/22/2010)[/b][hr]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[/quote]Unless you implement the update as an delete and an insert and something goes horribly wrong in between, I would be very surprised :-)</description><pubDate>Wed, 22 Dec 2010 08:13:52 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>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</description><pubDate>Wed, 22 Dec 2010 07:14:56 GMT</pubDate><dc:creator>paul.goldstraw</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>[quote][b]Toreador (12/22/2010)[/b][hr]I get a pile of errors when I run it - Cannot insert the value NULL into column 'Seq'.I eventually worked out that this is because I have ANSI_NULL_DFLT_ON set to False, so Seq was added as a Not Null column.This never normally affects me, as I always specify NULL or NOT NULL and don't rely on a default, but can anyone point me in the direction of where this might be set?[/quote]Right-click on the database in SSMS, select properties and in the properties editor select the options tab. There you can set the value for 'ANSI NULL default'. You can also use the sp_dboption procedure.</description><pubDate>Wed, 22 Dec 2010 05:16:33 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Good question.</description><pubDate>Wed, 22 Dec 2010 04:06:14 GMT</pubDate><dc:creator>jaganmohan.rao</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>I get a pile of errors when I run it - Cannot insert the value NULL into column 'Seq'.I eventually worked out that this is because I have ANSI_NULL_DFLT_ON set to False, so Seq was added as a Not Null column.This never normally affects me, as I always specify NULL or NOT NULL and don't rely on a default, but can anyone point me in the direction of where this might be set?</description><pubDate>Wed, 22 Dec 2010 03:59:21 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>The question itself was OK, as a test to see what output the T-SQL would give.But not OK for the purpose mentioned in the explanation, as there are other statements that will do it much better and faster (as Oleg has already mentioned).</description><pubDate>Wed, 22 Dec 2010 02:17:01 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Nice question, thanks also Oleg for the remark and link  to Triangular Joins.Regards,Iulian</description><pubDate>Wed, 22 Dec 2010 01:08:32 GMT</pubDate><dc:creator>Iulian -207023</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Good question. Thanks 'Oleg Netchaev' for query &amp; link.</description><pubDate>Tue, 21 Dec 2010 22:48:27 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>This is a good basic question, thank you. One thing I would like to point out is that the update script in question is more complex than it needs to be and it uses what Jeff Moden calls a triangular join, which is one of the most evil things one can do to kill performance of the T-SQL query. Of course back in the dark ages when we had to work with SQL Server 2000, the triangular joins were a necessary evil sometimes, but in nowadays when the end of support for SQL Server 2000 is long as ended and the end of support for SQL Server 2005 is looming (12 of April 2011), it is about time to stop the triangular joins insanity and take a look at the windowing functions instead. For example, the update in question can be easily restated like this:[code="sql"];with records (RecID, Seq) as(    select         RecID, row_number() over(partition by Value order by RecID)        from #Test)    update #Test    set         Seq = records.Seq        from #Test inner join records            on #Test.RecID = records.RecID;[/code]Please, please read Jeff's article: [url=http://www.sqlservercentral.com/articles/T-SQL/61539/]http://www.sqlservercentral.com/articles/T-SQL/61539/[/url]It is a true eye opener!Just my 2 cents.Oleg</description><pubDate>Tue, 21 Dec 2010 21:26:53 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>Sequence</title><link>http://www.sqlservercentral.com/Forums/Topic1038039-2875-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/71890/"&gt;Sequence&lt;/A&gt;[/B]</description><pubDate>Tue, 21 Dec 2010 20:30:29 GMT</pubDate><dc:creator>zulmanclock</dc:creator></item></channel></rss>