如何将一列的行数据放置到同一行的另一列 [英] how to put row data of a column to another column of same row

查看:156
本文介绍了如何将一列的行数据放置到同一行的另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql数据库表n中有两列想要在从前端插入数据的同时将第一列数据放到同一行的第二列.谢谢..

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..

推荐答案

您的标识种子列种子默认情况下必须设置为1.因此,在插入数据之前,请先读取Identity列的最后一个值,将其增加为1(或任何种子值,然后将其设置为第二列).

另一种好方法是为其编写触发器,该触发器将在对表执行任何插入操作时自动运行,该触发器必须通过标识列值来更新该特定列.

您可以尝试其中的任何一种,两者都可以正常工作.
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.


DECLARE @Count BIGINT
从表1中选择SELECT @ Count = COUNT(*)
SET @Count = @Count +1
插入表1(Column2)中的值(@Count);


上面必须一行.
DECLARE @Count BIGINT
SELECT @Count=COUNT (*) FROM Table1
SET @Count = @Count +1
insert into Table1 (Column2) Values (@Count);


Above must be in one line.


Exa:
insert into Table1 (Column1,Column2) Values (Textbox1.Text,Textbox1.Text);


现在,Column1& Column2数据将相同.


Now Column1 & Column2 Data Would be same.


这篇关于如何将一列的行数据放置到同一行的另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆