In Sqlserver RTRIM and LTRIM function exist, use it
select LTRIM( ' vipul_1 ') , RTRIM( ' vipul_1 ') , RTRIM( LTRIM( ' vipul_1 ') )
As the latest Sqlserver introduce the Trim function
Updated
SQL Server follows the ANSI/ISO SQL-92 specification, see this below links. For this you compare the string with LIKE
operator as suggested below.
Len function is also not work, use DATALENGTH instead of this (As last suggested).
Why the SQL Server ignore the empty space at the end automatically?
https://dba.stackexchange.com/questions/10510/behavior-of-varchar-with-spaces-at-the-end
Declare @table table (name varchar(50))
insert into @table values ('vipul_1'), ('ajay_1') , ('eeee_1') , ('vipul')
DECLARE @User_Name NVARCHAR(25)
SET @User_Name= 'vipul_1 '
if Exists (select * from @table where name = @User_Name and DATALENGTH(name) = DATALENGTH(@User_Name) )
Select 0
Else
Select 1
select * from @table where name like @User_Name
select * from @table where name = @User_Name
select * from @table where name = @User_Name and DATALENGTH(name) = DATALENGTH(@User_Name) --use DataLength for this