score:0
Accepted answer
select SUBSTRING(ImportCount,13,patindex('% schedule items%',ImportCount)-13) from table name
Read More
- MS-SQL - Extracting numerical portion of a string
- Reverse only numerical parts of string in sql server
- Extracting a number of specific length from a string in SQL Server
- Extracting sub string from a string in sql sever
- SQL Server : extracting the middle of a string
- Extracting date from SQL String
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
- Extracting a string from data field in sql server
- Extracting a word from string from n rows and append that word as a new col in SQL Server
- SQL query to show a portion of string value from a column
- SQL Server: extracting $#,### from a string
- Extracting Email Domain from string in sql
- Extracting mutiple values from an XML string stored in a SQL table
- How to concatenate text from multiple rows into a single text string in SQL Server
- How to insert a line break in a SQL Server VARCHAR/NVARCHAR string
- Pad a string with leading zeros so it's 3 characters long in SQL Server 2008
- How to replace a string in a SQL Server Table Column
- Remove all spaces from a string in SQL Server
- How to check for Is not Null And Is not Empty string in SQL server?
- SQL Case Sensitive String Compare
- SQL Server String or binary data would be truncated
- Sql Server string to date conversion
- How to strip all non-alphabetic characters from string in SQL Server?
- How to use NULL or empty string in SQL
- SQL Server: converting UniqueIdentifier to string in a case statement
- How to trim a string in SQL Server before 2017?
- How to strip HTML tags from a string in SQL Server?
- How to truncate string using SQL server
- SQL Server: Examples of PIVOTing String data
- varbinary to string on SQL Server
- Printing integer variable and string on same line in SQL
More questions with similar tag
- How to find list of databases from Security Logins?
- Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF
- Synchronise sql server changes between databases
- How to build parent-child hierarchies (starting from root) in SQL Server?
- How to connect to MSSQL by using pure javascript
- How to persuade ascmd.exe to make tables as output, not a XML file?
- Stored procedure runs successfully but fails when called from a job
- Unable to retrieve a column no XML
- sql sum duration within start and stop time stamps
- How can I create a SSIS package for SQL Server 2008 in a SQL Server 2014 environment?
- Can't access sqlcmd using username password
- DISTINCT with PARTITION BY vs. GROUPBY
- SQL MIN_ACTIVE_ROWVERSION() value does not change for a long while
- Split string and save it to temporary table
- how to retrieve 0 instead of NULL values when result set is 0 (Counting business days)
- perform SQL Server operations with windows user id from an ASP.NET page
- Error converting data type varchar to numeric. When try to compare numeric
- SQL Server query help... need to convert varchar to date
- How to reset a variable/sql record once a month automatically with asp.net/sql ?
- SQL Server multiple table JOIN
- 'Master-Detail' type query, defaulting 'Detail' values
- Avoid returning result set from stored procedure
- OracleBulkCopy ORA-26041 Error Leap Year in 1932
- How to Convert the db2 TRIM function into SQL Server
- How to insert date and time in European format into SQL Server from C#?
- Order column varchar with multiple dots. Like number
- Simple SQL help to update table
- What does this statement do @@RowCount > 0
- db.submitchanges 1 of 2 updates failed
- SSIS Flat File error "Text was truncated or one or more characters had no match in the target code page."
Source:
stackoverflow.com