有问题。 我有一张叫做消费者的桌子。 在该表中,有三列代表个人的出生日期。 问题是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 21After 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)更多推荐
发布评论