如何从 VARCHAR 列获取信息并从中创建新列 [英] How to get info from VARCHAR column and create new column out of it
本文介绍了如何从 VARCHAR 列获取信息并从中创建新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我无法解决的问题.
I have a problem that I can't figure out.
我有一张表,其中包含列 template_name,在每个模板中,它都以 _US、_EE(又名国家/地区)结尾.我必须把那部分放到一个新的 Country 专栏中.
I have the table where it has column template_name, in every template, it ends with _US, _EE (aka country). I have to get that part to a new column that is Country.
示例数据:
Template_name Country
Party_package_US US or USA
PARTY_Package_GB GB or England
Random_temp_DE DE or Germany
新列的输出可以只是最后三个字符.
The output to the new column can be just the three last characters.
我不知道我必须做什么样的查询才能得到那个结果.
I don't know what kind of query I have to do to get that result.
好的,我该怎么做才能将结果添加到表中的新列中?
Okay now, what can I do get that result to the new column in table?
UPDATE #silverpop_header
SET MARKET_AREA = a.template_name
FROM #silverpop_header pop
join dw.f_CRM a
ON pop.template_name = a.TEMPLATE_NAME
left join (
select
RIGHT(RTRIM(Template_name), 2) country
from dw.f_CRM )
它在 Sybase 上
It is on Sybase
推荐答案
如果你只需要最后两个字符
If you just need the last two characters
SELECT
SUBSTRING(Template_name,-2) AS 'Country'
FROM TABLE;
或者如评论中所述:
SELECT
RIGHT(Template_name,2) AS 'Country'
FROM TABLE;
这篇关于如何从 VARCHAR 列获取信息并从中创建新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文