Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 需要帮助创建包含来自另一个变量的数据的新变量';s字符串使用右/左和CHARINDEX_Sql_String_Variables_Right To Left_Charindex - Fatal编程技术网

Sql 需要帮助创建包含来自另一个变量的数据的新变量';s字符串使用右/左和CHARINDEX

Sql 需要帮助创建包含来自另一个变量的数据的新变量';s字符串使用右/左和CHARINDEX,sql,string,variables,right-to-left,charindex,Sql,String,Variables,Right To Left,Charindex,如果有人能帮助我,我会非常感激的。我想创建一个新变量,其中包含投资描述变量中的第二个数字 下面是可变投资描述中数据的一个小示例。因为第一个数字的大小发生了变化,所以我很难使用RIGHT和LEFT函数格式化它。我的最终目标是要有一个能够精确格式化的代码,以便在一个新的列中得到准确的数字 Investment_Description 4 Matching notifications. 11 inserts/Updates. 4000 Matching notifications. 12 inser

如果有人能帮助我,我会非常感激的。我想创建一个新变量,其中包含投资描述变量中的第二个数字

下面是可变投资描述中数据的一个小示例。因为第一个数字的大小发生了变化,所以我很难使用RIGHT和LEFT函数格式化它。我的最终目标是要有一个能够精确格式化的代码,以便在一个新的列中得到准确的数字

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.

使用上面的示例,我希望新变量的最终结果如下所示

New_Variable
11
12
12
1

下面是我原以为可以工作的代码的大致概念。但我很快发现我无法使用左右函数,因为投资描述中第一个数字的长度经常变化

SELECT 

   NH.Investment_Description,
   RIGHT(NH.Investment_Description, CHARINDEX('ations.', NH.Investment_Description)-1) AS New_Variable

FROM Notification_main NM
INNER JOIN Notification_hub NH ON NM.Notification_id = NH.Notification_id;



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);

是一个数据库。用你正在使用的数据库标记你的问题。