用于创建新列的SQL查询 [英] Sql query for creating a new column

查看:74
本文介绍了用于创建新列的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个列中有数据,名为ANNETTE W * LOW的名字。



i想要创建另一个名为Last name的列并放入所有数据姓氏后的姓氏*



输入是名字

ANNETTE W * LOW



out put required:



名字姓氏

ANNETTE W LOW



请求sql查询请







我尝试了什么:



............................... ..........

I have data in one column called first name in this format " ANNETTE W * LOW "

i want to make another column called Last name and put all the data in last name after *

input is first name
ANNETTE W * LOW

out put required :

first name last name
ANNETTE W LOW

request a sql query please



What I have tried:

.........................................

推荐答案

Quote:

do你知道怎么写查询吗?



这个过程我知道了

do you know how to write query ?

this process i'm aware off

它不是那样的工作。

我们不做你的工作对于你。

如果你想让别人写你的代码,你必须付钱 - 我建议你去Freelancer.com并在那里问。



但要注意:你得到了你付出的代价。支付花生,买猴子。



发展的概念就像这句话所暗示的那样:系统地运用科学和技术知识来满足特定的目标或要求。 BusinessDictionary.com [ ^ ]

这与有一个不一样快速谷歌并放弃,如果我找不到完全正确的代码。

所以要么付钱给别人去做,要么学会如何自己写。我们不是为你做这件事。

It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.


你需要做的第一件事是改变表格设计以添加新栏目

将列添加到表(数据库引擎)| Microsoft Docs [ ^ ]



第二件事需要知道如何要做的是更新表中的数据。

UPDATE(Transact-SQL)| Microsoft Docs [ ^ ]



自2000年以来,上述功能适用于每个版本的MS Sql Server。

困难的部分是创建更新表中已有内容所需的信息。

如果您有2016或2017版本,则可以使用STRING_SPLIT命令。

STRING_SPLIT(Transact-SQL)| Microsoft Docs [ ^ ]



如果您有早期版本,则需要找到要创建的脚本一个类似的函数。
First thing you are going to need to do is to ALTER the table design to add in the new column
Add Columns to a Table (Database Engine) | Microsoft Docs[^]

The second thing are going to need to know how to do is to UPDATE the data within the table.
UPDATE (Transact-SQL) | Microsoft Docs[^]

The above functions work on every version of MS Sql Server since 2000.
The hard part is going to be creating the information you need for updating what is already in your table.
If you have versions 2016 or 2017, there is a STRING_SPLIT command that you can use.
STRING_SPLIT (Transact-SQL) | Microsoft Docs[^]

If you have an earlier version, you will need to find the scripting to create a similar function.


DECLARE @Table TABLE(Name varchar(100))
insert into @Table values('ANNETTE W * LOW')
select Name,substring(Name,0,charindex('*',Name))FirstName ,SUBSTRING(Name,charindex('*',Name)+1,LEN(Name)-charindex('*',Name))LastName from @Table


这篇关于用于创建新列的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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