Based on the information, I would recommend creating a single column on the pertinent table to serve as an identity that SQL Server will automatically generate the needed value for you to increment the final value by one for each transaction in the table. This column may also be a good candidate to serve as the primary key with a clustered or non-clustered index. Then create a second column to store the incremented number and date. Then use the combination of the GETDATE() and DATEPART functions. When you insert a new record in the table, set a default on the column where you want to store this value to capture the identity value, a dash and the two-date year.
For More Information
- Dozens more answers to tough SQL Server questions from Greg Robidoux and Jeremy Kadlec are available here.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- Have a SQL Server tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL Server questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, SQL Server, DB2, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Microsoft SQL Server Installation
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.