Thursday 24 November 2016

Escape Characters Example in Sql Server

Escape Characters Example in Sql Server



Implement a Like Operator on a column Whose Column Contains '%' as a symbol
E.g:'Veere%ndra'

For achieving of this Consider a following Table Creation


Create a Table Like This

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[EMP](
[Empno] [int] NOT NULL,
[Ename] [nvarchar](50) NOT NULL,
[Job] [nvarchar](50) NULL
) ON [PRIMARY]

GO





Insert a Data as follows 
Insert Into EMP Values(1,'veere%ndra','DotNet')
Insert Into EMP Values(2,'Truyar','Testing')
Insert Into EMP Values(3,'Ansari','Java')

Now I want to find an employee details whose name contains %
SELECT * FROM emp  WHERE Ename LIKE '%\%%' ESCAPE '\';

No comments :

Post a Comment