Click here to Skip to main content
15,885,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone
I am creating my table cashbook (which is the part of my accounting software). in that
i already created my table as

create table cashbook(cno int primary key , voucherno int identity(1,1), date1 date , perticulars varchar(100),amount bigint , total bigint)


when we inserting values in that table all going ok
but my customer requirement is that can he insert back dated entries in that table means like that
VB
cno |  voucherno | date1| perticulars  |amount |total
1|1|2015-11-02|for personal |2000|6000  <br>
2|2|2015-11-03| for office expences | 4000 | 10000 <br>
3|3|2015-11-03|for office | 2000 |8000 

Now my customer requirement is that can he insert another value at voucherno 2  and date = 2015-11-03
then according to him our table will be
<pre lang="vb">cno |  voucherno | date1| perticulars  |amount |total
1|1|2015-11-02|for personal |2000|6000  &lt;br&gt;
2|2|2015-11-03| for office expences | 4000 | 10000 &lt;br&gt;
4|3|2015-11-02|for personal expences | 4000 | 14000 
3|4|2015-11-03|for office | 2000 |16000 &lt;br&gt;
</pre>



like that when i insert any value it automatically add the the last amount + current amount but when we can insert back dated entry it follows same rule


now my question is how do i adjust the identity column value for last record , current record and next all record
Posted

1 solution

You can insert explicit value in to an identity column using IDENTITY_INSERT ON

Check this article for further details-
How to insert values to identity column in SQL Server[^]

Hope, it helps :)
 
Share this answer
 
Comments
Member 11226258 7-Nov-15 1:25am    
Thank you sir for you valuable answer
But I don't have duplicate voucherno
when i set identity_insert on it accepts duplicate
my column voucher no entries must be unique
Suvendu Shekhar Giri 7-Nov-15 4:23am    
After you made the explicit insert, you should set IDENTITY_INSERT=OFF.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900