TSQL-使用简单选择时不显示文本

时间:2018-12-11 22:20:41

标签: sql-server tsql

我正在查询varchar列,但我不想看到该行中的第一个字符,但是我不确定如何对select语句执行此操作。有人知道吗?我会很感激的。

这是表中的值:

{\rtf1\ansi\ftnbj{\fonttbl{\f0 \fswiss Arial;}}{\colortbl ;\red255\green255\blue255 ;\red0\green0\blue255 ;\red0\green0\blue0 ;\red0\green0\blue255 ;\red0\green128\blue0 ;}{\stylesheet{\f0\fs20\cf0\cb1 Normal;}{\cs1\additive\cf0\cb1 Default Paragraph Font;}}\margl1440\margr1440\margt540\margb1440\headery540\footery720\formshade\sectd\marglsxn1440\margrsxn1440\margtsxn540\margbsxn1440\headery540\footery720\sbkpage\pgncont\plain\plain\fs20\pard\plain\fs20\cf0\sscharaux1\par\fs24\b Phone Note\fs20\b0\par\par\b Initial Intake:\b0\par

1 个答案:

答案 0 :(得分:0)

我能够使用CHARINDEXSUBSTRINGLEN的组合来做到这一点。

SQL示例

DECLARE @searchString AS VARCHAR(50)
SET @searchString = 'Initial Intake:\b0\par'

;WITH
source_data
AS
(
    SELECT tbl.* FROM (VALUES
      ( '{\rtf1\ansi\ftnbj{\fonttbl{\f0 \fswiss Arial;}}{\colortbl ;\red255\green255\blue255 ;\red0\green0\blue255 ;\red0\green0\blue0 ;\red0\green0\blue255 ;\red0\green128\blue0 ;}{\stylesheet{\f0\fs20\cf0\cb1 Normal;}{\cs1\additive\cf0\cb1 Default Paragraph Font;}}\margl1440\margr1440\margt540\margb1440\headery540\footery720\formshade\sectd\marglsxn1440\margrsxn1440\margtsxn540\margbsxn1440\headery540\footery720\sbkpage\pgncont\plain\plain\fs20\pard\plain\fs20\cf0\sscharaux1\par\fs24\b Phone Note\fs20\b0\par\par\b Initial Intake:\b0\par...HERE IS THE REST OF THE STRING')
    ) tbl ([Column1]) 
)
SELECT
    [new_column] = SUBSTRING([Column1], CHARINDEX(@searchString, [Column1]) + LEN(@searchString), LEN([Column1]) - CHARINDEX(@searchString, [Column1]))
FROM    
    source_data

db<>fiddle

结果

screenshot