Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come estrarre questa specifica sottostringa in SQL Server?

Combina il SUBSTRING() , LEFT() e CHARINDEX() funzioni.

SELECT LEFT(SUBSTRING(YOUR_FIELD,
                      CHARINDEX(';', YOUR_FIELD) + 1, 100),
                      CHARINDEX('[', YOUR_FIELD) - 1)
FROM YOUR_TABLE;

Ciò presuppone che la lunghezza del tuo campo non supererà mai 100, ma puoi rendere più intelligente tenerne conto, se necessario, utilizzando LEN() funzione. Non mi sono preoccupato perché c'è già abbastanza da fare lì dentro e non ho un'istanza su cui testare, quindi sto solo guardando le mie parentesi, ecc.