Skip to main content

Posts

Showing posts with the label TRIM function in SQL Server

SQL Server ANY keyword

ANY keyword is used with a WHERE or HAVING clause. ANY keyword operates on sub-queries that return multiple values. ANY keyword returns true if any sub-query values matched the condition. Syntax: --SELECT TABLE ROWS and Used of ANY Keyword. SELECT Id, Name FROM [dbo].[Tbl_Demo] WHERE Id = ANY ( SELECT Id FROM [dbo].[Tbl_Demo] WHERE Id = 2 ) -- Result looks like, Id Name -------------- 2 Aradhya -- CREATE TABLE CREATE TABLE [dbo].[Tbl_Demo]( [ID] [ int ] IDENTITY( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 500 ) NULL , [Age] [ int ] NULL , [IsActive] [ bit ] NULL , [IsDeleted] [ bit ] NULL , CONSTRAINT [PK_Tbl_Demo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO --INSERT TABLE ROWS SET IDENTITY_INSERT [dbo].[Tbl_Demo] ON GO INSERT [dbo].[Tbl_Demo] ([I...

TRIM function in SQL Server

TRIM function is used to removed the space of given strings. Two types of TRIM  function. i.e. 1.        RTRIM  function 2.        LTRIM  function The RTRIM function is used to remove the right side space of given string. The LTRIM function is used to remove the left side space of given string. The query using   LTRIM and RTRIM as given below. ALTER FUNCTION [dbo] . [TRIM_STRING] ( @TEXT_STRING NVARCHAR ( MAX )) RETURNS NVARCHAR ( MAX ) BEGIN      RETURN LTRIM ( RTRIM ( @TEXT_ STRING )) END