Вопрос

I'm using SQL Server 2008. With the below code that someone here helped me with, is it possible to cast or convert column2 from varchar(50) to numeric(10,0) within the same select statement? This is part of a stored procedure that imports a tabbed delimited text file. If I can't do this in the select, I'll probably create some intermediate temp tables. Thanks for any help.

SELECT column1
 , RIGHT(column2,CHARINDEX('-',REVERSE(column2))-1) as extracted
 , column3 
FROM myTable

Someone asked for sample data. column2 could have Bluebird Clinic-333 as a varchar. The result of the query would be 333 as a numeric. The question has already been answered, but I added that in case someone finds it helpful.

Это было полезно?

Решение

Maybe?

SELECT column1
 , CAST(RIGHT(column2,CHARINDEX('-',REVERSE(column2))-1) AS numeric(10,0)) as extracted
 , column3 
FROM myTable
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top