我不确定这是否可能,但如果特定值在该列中可用,我正在尝试提取字符串中的一定长度。然而,该列中有大量数据,其中可能存在值
MODEL_NUMBER
。
我试图只提取
MODEL_NUMBER
右侧的 10 个字符。我希望我的解释是有道理的。
select *
from dbo.table
where dbo.table.column like '%MODEL_NUMBER =%'
dbo.table.column
内的数据示例,它不是恒定的,因此位置总是可以改变:
if ('A' != 'D' and '' != '1') translate for simple rules where never_have_this_argument = 'A' and EVT_ID = 'SKYP_ER' and IF_ID = 'TEAM_DCS_IFD' and IF_DATA_SEQ = 1234567 and EVT_DATA_SEQ = 8866848 and DEST_SYS_ID = 'DCS' and IFD_ACTION = '[ALL]' and EVT_IF_DATA_SEQ = 8925456 and and MODEL_NUMBER= 312963532_1' and COMM_MODE_CD = 'SYNCD' and COMM_MTHD_ID = '' and MODE = 'SEAMLES'
如果目标是在字符串中查找
MODEL_NUMBER=
,并从示例字符串中提取其后的 10 个字符,例如:
if ('A' != 'D' and '' != '1') 转换为简单规则,其中 never_have_this_argument = 'A' 且 EVT_ID = 'SKYP_ER' 且 IF_ID = 'TEAM_DCS_IFD' 且 IF_DATA_SEQ = 1234567 且 EVT_DATA_SEQ = 8866848且 DEST_SYS_ID = 'DCS' 且 IFD_ACTION = '[ALL]' 且 EVT_IF_DATA_SEQ = 8925456 且 MODEL_NUMBER= 312963532_1' 且 COMM_MODE_CD = 'SYNCD' 且 COMM_MTHD_ID = '' 且 MODE = 'SEAMLES'
(强调我的)
然后你可以使用:
SELECT
SUBSTRING(column_name, CHARINDEX('MODEL_NUMBER=', column_name) + LEN('MODEL_NUMBER='), 10) AS ExtractedModelNumber
FROM dbo.table
WHERE column_name LIKE '%MODEL_NUMBER=%'