Solved

redo identity column

Posted on 2013-06-10
4
311 Views
Last Modified: 2013-06-18
I have a new set of tables for invoicing and we are inserting invoices manually from word and excel files. Right noow we are just entering them as we get them and will need to sort them by date and then have the new invoice numbers in that sequence.

How would I do that?
0
Comment
Question by:Shawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 250 total points
ID: 39236810
you can add one new column with identity and turn if off.

insert the data using below query

insert into table_name (your_id_col)
SELECT ROW_NUMBER() OVER (ORDER BY date_column) AS Id FROM yourTable

and once this is done, turn on rhe identity
0
 
LVL 13

Assisted Solution

by:sameer2010
sameer2010 earned 250 total points
ID: 39236885
Create the table with IDENTITY column COL1 and then run the query to insert into the same:
i.e. INSERT INTO NEW_TABLE(COL2, COL3) SELECT COL2, COL3 FROM YOUR_MANUAL_TABLE ORDER BY MANUAL_INVOICE_DATE ASC
0
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 39237046
0
 
LVL 1

Author Comment

by:Shawn
ID: 39243424
thanks everyone. I've been put on another project but should have time to test Friday.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question