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 «««12345»»»

Sequences II Expand / Collapse
Author
Message
Posted Tuesday, April 24, 2012 6:11 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, September 18, 2014 7:50 PM
Points: 5,322, Visits: 25,235
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
Post #1288835
Posted Tuesday, April 24, 2012 6:31 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, September 18, 2014 10:35 AM
Points: 1,825, Visits: 2,175
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
Post #1288846
Posted Tuesday, April 24, 2012 7:02 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 12, 2014 7:18 PM
Points: 1,325, Visits: 1,693
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!
Post #1288889
Posted Tuesday, April 24, 2012 7:05 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 12:58 PM
Points: 2,561, Visits: 3,842
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.
Post #1288890
Posted Tuesday, April 24, 2012 9:24 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 8:36 AM
Points: 3,918, Visits: 3,638
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.
Post #1289079
Posted Tuesday, April 24, 2012 9:26 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:53 AM
Points: 1,176, 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

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

Cheers
Post #1289084
Posted Tuesday, April 24, 2012 9:41 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 11:38 PM
Points: 1,994, Visits: 10,966
Great question. Looking forward to using this feature in an upcoming project....


Rob Schripsema
Accelitec, Inc
Post #1289111
Posted Tuesday, April 24, 2012 9:56 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:19 AM
Points: 2,963, Visits: 2,982
Good one
...[-2147483648,-2147483647, ... ,2147483646,2147483647],[-2147483648,-2147483647, ... ,2147483646,2147483647]...

IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1289131
Posted Tuesday, April 24, 2012 10:08 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, September 18, 2014 2:58 PM
Points: 3,776, Visits: 1,176
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.
Post #1289147
Posted Tuesday, April 24, 2012 11:03 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:54 AM
Points: 4,107, Visits: 3,423
Thanks for an easy one!
Post #1289209
« Prev Topic | Next Topic »

Add to briefcase «««12345»»»

Permissions Expand / Collapse