home page
about us
consulting service
maintenance plan
training
faqs
hints and tips
resources
how to
testimonials
news
blog
case studies
clients
register
log in
contact us
DECLARE @CompanyName VARCHAR(50) SET @CompanyName= 'Testing My Code Ltd' SELECT LEFT(@CompanyName, ISNULL(NULLIF(CHARINDEX('-', @CompanyName) - 1, -1), LEN(@CompanyName))) AS [Company Name]
Since there's no dash in the company name, the whole company name is returned as the Company Name field.
A function was then created to extract only the company name from company name field of the database.
CREATE FUNCTION [dbo].[ufn_CompanyName]( @fCompanyName VARCHAR(50)) RETURNS VARCHAR(50) AS BEGIN RETURN LEFT(@fCompanyName, ISNULL(NULLIF(CHARINDEX('-', @fCompanyName) - 1, -1), LEN(@fCompanyName))) END