我在SQL Server中有以下表格:
Value String (csv) Name Color
-------------------------------------------------------------------
1 Simi,123456,abc@123,Blue,45 Simi Dog
我想从csv字符串中提取“Blue”并更新颜色列中的值。
Value String Name Color
-------------------------------------------------------------------
1 Simi,123456,abc@123,Blue,45 Simi Blue
答案 0 :(得分:1)
UPDATE yourTable
SET Color = SELECT REVERSE(SUBSTRING(REVERSE(String),
CHARINDEX(',', REVERSE(String)) + 1,
CHARINDEX(',', REVERSE(String), CHARINDEX(',', REVERSE(String)) + 1) - CHARINDEX(',', REVERSE(String)) - 1))