如何将一列数据复制到另一列而不删除接收列中的数据(How to copy one column of data to another without deleting data in receivin

系统教程 行业动态 更新时间:2024-06-14 16:59:46
如何将一列数据复制到另一列而不删除接收列中的数据(How to copy one column of data to another without deleting data in receiving column)

有问题。 我有一张叫做消费者的桌子。 在该表中,有三列代表个人的出生日期。 问题是DOB分为年,月,日。 我想做的是将月和日列数据复制到年份列。

恩。

year month day 1971 05 21

运行脚本后,我希望年份列中包含此值: 19710521

然后我还想运行一个脚本来删除前2个整数(1971年的“19”)

have an issue. I have a table called consumers. In that table there are three columns that represent the date of birth of an individual. Problem is the DOB is split into year, month, day. What I'd like to do is copy over the month and day column data to the year column ..

ex.

year month day 1971 05 21

After running the script, I'd like the year column to have this value in it: 19710521

Then I'd also like to run a script to delete the leading 2 integers (the "19" of the 1971)

最满意答案

update consumers set year=cast(year as varchar(4))+cast(month as varchar(2))+cast(day as varchar(2))

这会将数据复制到年份列

如果年份列是int那么

update consumers set year=cast(cast(year as varchar(4))+cast(month as varchar(2))+cast(day as varchar(2)) as int)

删除前2个数字

update consumers set year= SUBSTRING(cast(year as varchar(50)),3,LEN(year)-2) update consumers set year=cast(year as varchar(4))+cast(month as varchar(2))+cast(day as varchar(2))

this will copy data to year column

if year column is int then

update consumers set year=cast(cast(year as varchar(4))+cast(month as varchar(2))+cast(day as varchar(2)) as int)

to remove first 2 numbers

update consumers set year= SUBSTRING(cast(year as varchar(50)),3,LEN(year)-2)

更多推荐

本文发布于:2023-04-17 08:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e2a1a3768d6e689a944979c90a871fa4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   而不   如何将   copy   receiving

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!