Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Query as follows

i have one table as follows control_file

ctrl_type   ctrl_last_no
 PKGNO         52


I have another table as follows Co_Package_Master

cpm_pkg_id   pkg_name
 PKG00000     EFA+PSSR


First Query as follows
SQL
Update control_file set ctrl_last_no = ctrl_last_no + 1 where ctrl_type = 'PKGNO'


Second Query as follows
SQL
select * from CONTROL_FILE where ctrl_type = 'PKGNO'


i get the ctrl_last_nor from control file table and increment one
i have Co_package_master table in that i want to insert the cpm_pkg_id as follows
PKG0000053

The above 53 value has get from control file and increment one value and want to be store in the co_package_master table.

for that how can i do in asp.net using c#.
Posted
Updated 14-Sep-15 9:01am
v2
Comments
PIEBALDconsult 14-Sep-15 1:14am    
Which database system?
Sinisa Hajnal 14-Sep-15 1:27am    
Second query will occasionally return the wrong number. This will happen when two users increment at the same time. Database will dutyfuly update twice and both your users will get the same number back. I would advise you to put ctrl_last_no +1 into a variable, do the update then immediately (in the same stored procedure - or transaction if you're calling from the code) call insert.
deepankarbhatnagar 14-Sep-15 3:39am    
Have you done any coding?

1 solution

first get last record.
SQL
select top 1 ctrl_last_no from CONTROL_FILE where ctrl_type = 'PKGNO' order by ctrl_last_no desc.



than store it any int variable than increment and insert in another table . or you can also write a stroed procedure/trigger for all above tasks(which is better approach)
 
Share this answer
 
v3

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