SQL Server - how to find a substring in a column

Asked By Pushpa on 24-Mar-10 07:02 PM
end of post
nanda Kishore replied to Pushpa on 24-Mar-10 08:48 PM
  string s = "John Matthew";
            Console.WriteLine("First Name:"+ s.Substring(4)); 
            Console.WriteLine("Last Name:"+ s.Substring(0,4)); 
            Console.ReadLine();
 refer below site for more info
http://dotnetperls.com/substring
Appari NRao replied to Pushpa on 24-Mar-10 09:14 PM
In SQLServer use substring function,
it has three parameters
1. original string
2. start index
3. length of the substring to extract

refer BOL for more help on substring function.

sample:
the following SQL statement returns value 'st Va'
select substring('Test Value',3,5)
F Cali replied to Pushpa on 24-Mar-10 10:43 PM
One way to search for a string (or substring) in a column is with the use of the LIKE clause:

SELECT * FROM [dbo].[Employees]
WHERE [FirstName] LIKE '%Ron%'

This will return all employees where their first name has the string "Ron" (case insensitive), whether the string is at the beginning or at the end since the wild-card "%" was specified both at the start and at the end.  If you just want anything that starts with a certain string, then just put the wild-card at the end:

SELECT * FROM [dbo].[Employees]
WHERE [FirstName] LIKE 'John%'

Regards,
http://www.sql-server-helper.com/sql-server-2008/index.aspx
Super Man replied to Pushpa on 25-Mar-10 12:23 AM

Select *

From table1

Where name like ‘%pushpa%;

 

O/p:

Apushpahdsfkj

Hsdjkfhspushpasdfsdf

Pushpasdfsjf

adfsdpushpa

 

% is wild character ,it means before pushpa name there can be zero or more than zero  charcter.

 

Select *

From table1

Where name like ‘_pushpa%;

o/p:

apushpasdfkjdsh

bpushpadjfkjsdh

cpushpa

 

_ it means there can be atleast and only one characterberfore name pushpa. At the end % is used which represent s     >=0    character.