我正在創建一個查詢以獲取字串列中 2 個問題之間的答案,因此示例資料基本上如下所示:
1. Over the past two weeks, have you felt down, depressed or hopeless? NO 2. Over the past two weeks, have you felt little interest or pleasure in doing things?
所以我只需要得到“否”的答案,格式總是一樣的
uj5u.com熱心網友回復:
文本格式不正確。如果您可以在問題和答案之間添加一個簡單的字符,那么將有一個簡單的解決方案:請參閱我的示例:
DECLARE @String NVARCHAR(4000) = N'1. Over the past two weeks, have you felt down, depressed or hopeless? NO ;2. Over the past two weeks, have you felt little interest or pleasure in doing things? YES';
SELECT SUBSTRING(ss.value, 0, CHARINDEX('?', ss.value) 1) AS Question, SUBSTRING(ss.value, CHARINDEX('?', ss.value) 1, LEN(ss.value)) Answer
FROM STRING_SPLIT(@String, ';') AS ss;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/504863.html