Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Auto increment in an insert statement from a varchar field

$
0
0

We need to create several records via bulk insert in SQL Server 2008 R2. The problem we are experiencing is with one varchar field that must be populated. This varchar field begins with two letters (always the same) then adds the current date (yymmdd) and then adds a three digit integer sequence. The three digit sequence is indicative of the number of records created in the table on that date (001 - 999). The max number of records that can be created on any given date is 999 and we've accounted for that in the bulk insert, but we can't figure out how to get the last part of the statement to auto increment the last three digits.

Example, every record created in this table today is prefixed with YN160607. We've got the script to account for that as 'YN' + convert(varchar(6),GETDATE(),12)

We plan to run this bulk insert when the business...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>