Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Syntax for using Left and Replace

Author  Topic 

cheesythestar
Starting Member

3 Posts

Posted - 2009-01-30 : 16:26:51
I need to replace certain characters in the field and then use upto 5 characters from the field's value to compare it with a value with some other table. What is the syntax to use both replace and left in this..
It would be great if I am able to get some help in this regard.


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-30 : 16:29:43
The syntax for LEFT and REPLACE can be found in SQL Server Books Online. To help write your query though, we'll need to see a data example.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cheesythestar
Starting Member

3 Posts

Posted - 2009-01-30 : 16:35:41
I found the syntax to write using left first and then REPLACE. However i would first like the REPLACE commands to give the output and then i would need to use LEFT operator on it..
Thanks

Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-30 : 16:51:20
So something like this?

SELECT LEFT(REPLACE('abcdefg','abc','123'),4)

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-30 : 19:01:51
You didn't provide a data example, so it's hard to assist you with this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Rajesh Jonnalagadda
Starting Member

45 Posts

Posted - 2009-01-31 : 07:02:47
Try this,

SELECT REPLACE('TEST_FORUMS', '_', '+')
SELECT LEFT('TEST_FORUMS', 4)

Rajesh Jonnalagadda
[url="http://www.ggktech.com
"]GGK TECH[/url]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-31 : 08:12:40
quote:
Originally posted by cheesythestar

I found the syntax to write using left first and then REPLACE. However i would first like the REPLACE commands to give the output and then i would need to use LEFT operator on it..
Thanks




show some sample data and output you want if you need exact solution.
Go to Top of Page

cheesythestar
Starting Member

3 Posts

Posted - 2009-02-05 : 13:14:19
Thanks for the suggestions.. This one worked ..SELECT LEFT(REPLACE('abcdefg','abc','123'),4)....

Go to Top of Page
   

- Advertisement -