微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要帮助,使用RIGHT / LEFT和CHARINDEX创建一个包含另一个变量的字符串中的数据的新变量

如何解决需要帮助,使用RIGHT / LEFT和CHARINDEX创建一个包含另一个变量的字符串中的数据的新变量

如果有人可以帮助我,我将非常感激。我想在Investment_description变量中创建一个包含第二个数字的新变量。

下面是变量investment_description中数据的一个小示例。我很难使用RIGHT和LEFT函数对其进行格式化,因为第一个数字的大小发生了变化。我的最终目标是拥有可以正确格式化其格式的代码,以便在新列中获取确切的数字。

const accounts = msalApp.getTokenCache().getAllAccounts();
// filter on the account that you want to delete from the cache.
// I take the first one here to keep the code sample short
const account = accounts[0];
msalApp.getTokenCache().removeAccount(account);

使用上面的示例,我希望新变量的最终结果看起来像这样

<form class="user" method="post" action="<?= base_url('AdminUpdateProfile/edit/'.$user['id']); ?>" enctype="multipart/form-data">

     your code here

</form>

下面是我认为本来可以工作的代码的粗略概念。但是我很快发现我无法使用LEFT和RIGHT函数,因为Investment_Description中第一个数字的长度经常改变长度。

Investment_Description 
4 Matching notifications. 11 inserts/Updates.
4000 Matching notifications. 12 inserts/Updates.
32 Matching notifications. 12 inserts/Updates.
171 Matching notifications. 1 inserts/Updates.

解决方法

SQL Server不太支持字符串操作,但是您可以使用:

select  left(v.val1,charindex(' ',v.val1) - 1)
from (values ('32 Matching notifications. 12 inserts/Updates.')
     ) t(Investment_Description) cross apply
     (values (stuff(t.Investment_Description,1,charindex('. ',t.Investment_Description) + 1,''))
     ) v(val1);

Here是db 小提琴。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。