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

Generated Sequences with SQL Server Expand / Collapse
Author
Message
Posted Wednesday, November 28, 2012 9:33 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
Does SQL Server Express support all programmability features?

Is a sequence a function or DDL trigger?

I am using this as a reference
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

Objective:

Create a Waste Hauler Unique Number. For instance, 00000-V/C 0000- AT- YR
Post #1389914
Posted Wednesday, November 28, 2012 9:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
I guess I need to know where I need to start from.
Post #1389917
Posted Wednesday, November 28, 2012 9:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:24 PM
Points: 11,990, Visits: 11,007
sasansamani (11/28/2012)
Does SQL Server Express support all programmability features?


What do you mean by this?


Is a sequence a function or DDL trigger?


You posted this in the 2005 section so I assume you are using 2005? SQL 2012 introduced the sequence. It is an object but not a function or a ddl trigger.


I am using this as a reference
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

Objective:

Create a Waste Hauler Unique Number. For instance, 00000-V/C 0000- AT- YR


I am guessing that you want to create some sort of incrementing complex value? This is almost always a bad idea because it it a nightmare to get right. Concurrency is a real issue with a roll your own type of solution. There is lots of pain and little to gain. It would be far easier to use an identity as one column and the rest of the "key" in a second column.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1389930
Posted Wednesday, November 28, 2012 10:03 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
thank you for your reply.

Can I use the Identity Property in SQL express 2008?
Post #1389944
Posted Wednesday, November 28, 2012 10:09 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 11:24 AM
Points: 32,781, Visits: 14,942
yes, identity is supported in all versions of SQL Server.






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1389953
Posted Wednesday, November 28, 2012 10:24 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
Let me explain what exactly we are trying to do.

Waste Hauler Unique Number Example: 00000-V/C 0000- AT- YR

Requirements:

Hauler # = 00000 (permanent)- there may be 1000 hauler companies
Asset = V / C (vehicle or container + permanent #)
Material/Classification = AT (landfill / temporary)- this may be different
(Material: A- Landfill B-Recycling C-Compost)(Classification: T- Temporary P- Permanent)
YR = Year (2013)

So the best way to implement this is to use the Identity Property? Is that correct?

I just need to know a logical way to implement this.
Post #1389970
Posted Wednesday, November 28, 2012 10:33 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:24 PM
Points: 11,990, Visits: 11,007
sasansamani (11/28/2012)
Let me explain what exactly we are trying to do.

Waste Hauler Unique Number Example: 00000-V/C 0000- AT- YR

Requirements:

Hauler # = 00000 (permanent)- there may be 1000 hauler companies
Asset = V / C (vehicle or container + permanent #)
Material/Classification = AT (landfill / temporary)- this may be different
(Material: A- Landfill B-Recycling C-Compost)(Classification: T- Temporary P- Permanent)
YR = Year (2013)

So the best way to implement this is to use the Identity Property? Is that correct?

I just need to know a logical way to implement this.


Not sure exactly what you are trying to do from this. Are you wanting a single column to have all this information?

If I were going to generate a table to hold this data it would look something like this.

create table #Haulers
(
HaulerID int identity primary key,
Asset char(1),
Classification char(2),
Material char(1),
DateCreated datetime not null default getdate()
)




_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1389977
Posted Wednesday, November 28, 2012 10:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
Our department wants to automatically generate permit numbers for our customers when they apply for a license.They want something similar to a key generator. Yes SQL Server is my only resource at this moment.
Post #1389993
Posted Wednesday, November 28, 2012 11:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:24 PM
Points: 11,990, Visits: 11,007
sasansamani (11/28/2012)
Our department wants to automatically generate permit numbers for our customers when they apply for a license.They want something similar to a key generator. Yes SQL Server is my only resource at this moment.


I can help but you have to help me understand the scope of what you are trying to do. Is there a certain format you need this to be in? Is there any reason these permit numbers can't be numeric?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1390011
Posted Wednesday, November 28, 2012 11:37 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
Sean Lange (11/28/2012)
sasansamani (11/28/2012)
Our department wants to automatically generate permit numbers for our customers when they apply for a license.They want something similar to a key generator. Yes SQL Server is my only resource at this moment.


I can help but you have to help me understand the scope of what you are trying to do. Is there a certain format you need this to be in? Is there any reason these permit numbers can't be numeric?


This is the format they want 00000-V/C 0000- AT- YR

They want to be able distinguish if it’s a vehicle or container. They want to be able distinguish if it’s a temporary or permanent. It can’t be a numeric permit number.
Post #1390019
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse