I am trying to extract a certain amount of length in string if the specific value is available inside that column. The column however has a lot of data in it which where the value MODEL_NUMBER may be present.
I am trying to only extract 10 characters to the right of MODEL_NUMBER. I hope my explanation makes sense.
select *
from dbo.table
where dbo.table.column like '%MODEL_NUMBER =%'
Example of data within dbo.table.column which isn't constant so the position can always change:
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'
and EVT_IF_DATA_SEQ = 8925456 and and MODEL_NUMBER= 312963532_1'). Some values have quotes around them, others don't (and one is only quoted on the right hand side)... You really need to fix the design here, that is the only real solution, and future you will be extremely greatful.CHARINDEXandSUBSTRINGare likely to be of help. If you try using them and can't get it working, please edit your question and show us the code you've tried.%MODEL_NUMBER =%but your string hasMODEL_NUMBER= 312963532_1which won't match already since space is on the wrong side of the equals. Also, you should include your desired result for this string. But feel free to play around withselect substring(x.str, patindex('%MODEL_NUMBER= %', x.str) + datalength('MODEL_NUMBER= '), 10) from yourtable x