Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sequences II


Sequences II

Author
Message
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5687 Visits: 25280
Thomas Abraham (4/24/2012)
bitbucket-25253 (4/24/2012)
... 2nd select returns 2147483646 yes the sequence is descending, but still not what is the supposed correct answer, so I am still confused and perplexed.


Now I'm confused. What do you think is the supposed answer? I answered, and the answered page shows as correct 2147483646.


My apologies .... YOU ARE CORRECT

I should have finished my first cup of coffee before even attempting to answer and then wondering why what I selected was incorrect.

Again My apologies -

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Thomas Abraham
Thomas Abraham
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2329 Visits: 2254
bitbucket-25253 (4/24/2012)
My apologies .... YOU ARE CORRECT

I should have finished my first cup of coffee before even attempting to answer and then wondering why what I selected was incorrect.

Again My apologies -



No apology necessary. However, it should demonstrate the esteem your signature carries that, in spite of getting it correct, I was willing to consider that you saw something I didn't.

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
sknox
sknox
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2030 Visits: 2707
Thomas Abraham (4/24/2012)
I think if you give it some thought, this feature behaves as you would design it. The defaults seem the way I would hope they would - for a pleasant change.


Exactly. I heard of sequences at Dev Connections last month, and immediately thought of some "gotchas" that might make them somewhat difficult to work with. So I wrote some tests, whence came these questions (there's one more in the sequence by the way ; )

Every test I tried worked. Essentially, from what I could tell, you have to ignore the defaults or deliberately do something odd to break sequences in SQL 2012.

So (and I don't say this very often) Bravo, Microsoft!
OCTom
OCTom
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2813 Visits: 4152
sqlmunkee (4/24/2012)
So, the key bit here is that SQL will *decide* whether the sequence is ascending or descending based on the INCREMENT BY argument. That's a bit misleading if your just starting out with sequences and SQL 2012 (like me) :-) Good question !


I agree that it seems misleading or confusing. That's why I always code the details even if they are the defaults and not required. That way, there is no question when someone else reads the code. It gets a little wordy but it alleviates confusion.

It's good to learn the new stuff. :-)
Cliff Jones
Cliff Jones
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4069 Visits: 3648
OCTom (4/24/2012)
sqlmunkee (4/24/2012)
So, the key bit here is that SQL will *decide* whether the sequence is ascending or descending based on the INCREMENT BY argument. That's a bit misleading if your just starting out with sequences and SQL 2012 (like me) :-) Good question !


I agree that it seems misleading or confusing. That's why I always code the details even if they are the defaults and not required. That way, there is no question when someone else reads the code. It gets a little wordy but it alleviates confusion.

It's good to learn the new stuff. :-)


Good point, always code the details which should remove any ambiguity or confusion.

Good question.
OzYbOi d(-_-)b
OzYbOi d(-_-)b
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1300 Visits: 778
Toreador (4/24/2012)
Thomas Abraham (4/24/2012)
this feature behaves as you would design it.


Which is the reason I guessed wrong ;-)


+1 :-D

Great question. Need to dig into the new 2012 features more.

Cheers
Rob Schripsema
Rob Schripsema
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2319 Visits: 11042
Great question. Looking forward to using this feature in an upcoming project....

Rob Schripsema
Propack, Inc.
Igor Micev
Igor Micev
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4162 Visits: 4843
Good one
...[-2147483648,-2147483647, ... ,2147483646,2147483647],[-2147483648,-2147483647, ... ,2147483646,2147483647]...

IgorMi


Igor Micev,SQL Server developer at Seavuswww.seavus.com
EL Jerry
EL Jerry
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3914 Visits: 1337
Excellent question. I had to read and re-read BOL to get it right. Seems that sequences with default values are tricky to understand, but I found that reading the specific points make sense to their behavior.

From BOL (http://msdn.microsoft.com/en-us/library/ff878091.aspx):

START WITH <constant>
The first value returned by the sequence object. The START value must be a value less than or equal to the maximum and greater than or equal to the minimum value of the sequence object. The default start value for a new sequence object is the minimum value for an ascending sequence object and the maximum value for a descending sequence object.

INCREMENT BY <constant>
Value used to increment (or decrement if negative) the value of the sequence object for each call to the NEXT VALUE FOR function. If the increment is a negative value, the sequence object is descending; otherwise, it is ascending. The increment cannot be 0. The default increment for a new sequence object is 1.


"El" Jerry.

"El" Jerry.

"A watt of Ottawa" - Gerardo Galvan

To better understand your help request, please follow these best practices.
Revenant
Revenant
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5760 Visits: 4704
Thanks for an easy one!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search