Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i've two columns in sql database table n want to put first column data to second column on same row while inserting data from front end.i'm using in-line query.. coding with example is helpful.. thanks..
Posted

your identity seed column seed must be set to one by default. So before inserting the data, read the last value of your identity column, increase it be one (or whatever your seed value is, and set it into second column.

Another, good way is writing a trigger for it which will automatically run whenever any insert is performed on the table, this trigger must update that particular column by the identity column value.

You can try any of these, both will work fine.
 
Share this answer
 
DECLARE @Count BIGINT
SELECT @Count=COUNT (*) FROM Table1
SET @Count = @Count +1
insert into Table1 (Column2) Values (@Count);


Above must be in one line.
 
Share this answer
 
Comments
Pawan Kiran 21-Oct-10 8:18am    
nice one.

i think we can use this also
select @Count=Max(Column1) From Table1
arindamrudra 21-Oct-10 8:27am    
This two (I mean my answer and your answer) have some limitations. Because both of the cases need the logical deletion. If physical deletion occurs, then problem will appear. The answer of Mr. Anurag Gupta is the more appropriate than us (I think).
Pawan Kiran 21-Oct-10 8:40am    
ya, your words are true.
@nuraGGupta@ 21-Oct-10 8:53am    
Thanks for the appreciation Arindam.
Exa:
insert into Table1 (Column1,Column2) Values (Textbox1.Text,Textbox1.Text);

Now Column1 & Column2 Data Would be same.
 
Share this answer
 
It's very simple


insert into tablename (column1,column2) values (@parameter1,@parameter1)


Try This
 
Share this answer
 

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