.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Sql Server Trim function

Posted By: Naresh     Posted Date: June 10, 2010    Points:2   Category :Sql Server
Hi,

Can i use trim function in where condition.

eg:

table1_1

id name address
1 aaa Chennai
2 ggg Coimbatore
3 fff delhi


table1_1

id name address
1 aaa Chennai
2 ggg Coimbatore
3 mmm delhi


i need to display the commman id and name in both tables.

The result i want is
id name address
1 aaa Chennai
2 ggg Coimbatore

How can i use trim funtion in name while comparing



Thanks
Naresh

Responses
Author: Amit Mehra             
Posted Date: June 10, 2010     Points: 5   

Hi,

Yes you can use RTrim and LTrim function in SQL server in where clause.

for eg

ltrim(rtrim(@anme))


Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: jay             
Posted Date: June 10, 2010     Points: 5   

let second table name be table_2

select a.id,a.name,a.address from table1_1 as a inner join table_2 as b
on ltrim(rtrim(a.name))=ltrim(rtrim(b.name))

Author: Suresh             
Posted Date: June 10, 2010     Points: 5   

Hello Naresh,
Kindly try below one.
Declare @t table
(
area nvarchar(50)
)
insert into @t
Select ' Coimbatore' union all -- here you give left space value
Select 'Ganapathy ' --- here you give right space value

Select * from @t
Select area from @t where ltrim(area)='Coimbatore'
Select area from @t where area='Ganapathy '
--Select ltrim(area) from @t


You no need to provide rtrim,sqlservice engine take care its automatically.
Let me know that, do you need any clariffication further.


Author: Naresh             
Posted Date: June 11, 2010     Points: 5   

Hi jay thank u for replaying

U query worked.


Thanks to amit and suresh too


Thanks
Naresh


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend