SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 No Replace All Type Command
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sinjin67
Yak Posting Veteran

USA
53 Posts

Posted - 12/27/2008 :  19:25:20  Show Profile  Reply with Quote
As I am reading more and more on SQL and coming
from a Foxpro logic. I take it their is no real
"Replace All" type command in SQL and it appears
I would want to use an "Update".

I was hoping one of the SQL Masters might be
able to share some background on this or
perhaps a link on transitioning from Foxpro to
SQL with regards to the Replace function.

I am happy to read on my own. Its just information
seems to be limited and a little confusing..

Peace.

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 12/27/2008 :  20:16:49  Show Profile  Reply with Quote
I'm certainly no SQL Master, and don't know FoxPro at all. There is a REPLACE function in SQL.
DECLARE @var varchar(5)
SET @var = 'ababab'
SELECT REPLACE(@var,'a','c')
gives 'cbcbcb'
To change an entire column of 'ababab' with 'cbcbcb'
UPDATE yourTable
SET yourColumn = REPLACE(yourColumn,'a','c')
Books On Line is a great place to learn about SQL, and how you would do things in SQL that you did on FoxPro.

Jim
Go to Top of Page

Dan OHaver
Starting Member

1 Posts

Posted - 12/27/2008 :  23:12:58  Show Profile  Reply with Quote
Although I am not a SQL Master, I have transitioned a few database projects from Foxpro to SQL Server. I do not know of a book that specifically deals with this topic.

You are correct, T-SQL UPDATE replaces the REPLACE statement in Foxpro:

For example, to increase a retail price by 20% for all items:

FOXPRO
Replace ALL Price with Price * 1.20 in Products

SQL
UPDATE Products
SET Price = Price * 1.20

Please note, you can use nearly all basic T-SQL language in Foxpro; the UPDATE example above works in Fox as well (you'll need to put a ; in the line break after "Products").

The best resource may be to read a good book on beginning T-SQL and just plow through it.

Delete, like the UPDATE/Replace is an area you’ll need to focus on as well as any type of Foxpro SCAN … ENDSCAN areas in your FOX code.

You might find what you need right in Foxpro help, look up DELETE-SQL, UPDATE-SQL, SELECT-SQL in Foxpro’s help system.

Any SCAN…ENDSCAN code could be difficult to convert, not that it can’t be done with Cursors in SQL, but this is typically frowned upon in a SQL environment. Try to replace the looping functionality with a single UPDATE.



Edited by - Dan OHaver on 12/27/2008 23:20:36
Go to Top of Page

sinjin67
Yak Posting Veteran

USA
53 Posts

Posted - 12/28/2008 :  01:45:34  Show Profile  Reply with Quote
Thank you for the tips..It really helps.
I did get 2 begineer books for T-Sql and
have be working them..The example given also
gave form so I can work and learn from that.
The trouble starts when I go back to foxpro
command I know by heart and expect it to work..
I am sure you all understand, I have a learning
curve but I am getting there..
Thanx again..
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.19 seconds. Powered By: Snitz Forums 2000