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

Come separare la data da una stringa?

declare @txt varchar(max)
set @txt = 'on 01-15-09 witha factor of 0.8'

select cast(substring(@txt, patindex('% [0-9][1-9]-%', @txt), 9) as date) [date], 
cast(right(@txt, patindex('%_ %', reverse(@txt))) as decimal(9,1)) Factor

Risultato:

date       Factor
---------- ------
2009-01-15 0.8