score:0

Accepted answer
select SUBSTRING(ImportCount,13,patindex('% schedule items%',ImportCount)-13) from table name

Read More

score:0

Try this..You can declare it as a SQL function also.

DECLARE @intText INT
DECLARE @textAplhaNumeric varchar(100)

set @textAplhaNumeric = '1376 schedule items imported from location'
SET @intText = PATINDEX('%[^0-9]%', @textAplhaNumeric)

BEGIN
WHILE @intText > 0
BEGIN
SET @textAplhaNumeric = STUFF(@textAplhaNumeric, @intText, 1, '' )
SET @intText = PATINDEX('%[^0-9]%', @textAplhaNumeric)
END
END

Select @textAplhaNumeric //output is 1376

It will work in case of NULL or empty values.

score:0

Please try:

SELECT LEFT(Val,PATINDEX('%[^0-9]%', Val+'a')-1) from(
    SELECT
       STUFF(ImportCount, 1, PATINDEX('%[0-9]%', ImportCount)-1, '') Val
    FROM YourTable
)x

score:1

Try

select left(ImportCount, patindex('%[^0-9]%', ImportCount+'.') - 1)

More questions with similar tag