I have a table that contains a column with values stored as varchars (text) as following
I need to select the column to return
If you always have one nominator and one denominator, than something like this could work.
DECLARE @t TABLE(s VARCHAR(100)); INSERT @t (s) VALUES ('150/5'), ('200/5'); WITH CTE AS( SELECT CAST(LEFT(s,CHARINDEX('/',s)-1) AS INT) AS first, CAST(SUBSTRING(s,CHARINDEX('/',s)+1,LEN(s)) AS INT) AS second FROM @t )SELECT first,second,first/second FROM cte;
Guess there are more elegant ways of doing it, and this would break if there's not exactly one '/' in the column.
16 People are following this question.