I have a requirement where I need to convert Foxpro SQL syntax to SQL Server. What should be appropriate equivalent of below Foxpro code in SQL Server?
Here is complete statement:
Its a DBF Update statement in FoxPro:
REPLACE ALL Column1 WITH "N/A" FOR Column2="Some string value"=.f.
I want to understand what the Column2="Some string value"=.f. part means.
A per my assumption this code corresponds to below code in SQL Server:
columnName <> "String Value"
Please advise!
As per the handy unofficial backup mirror of the FoxPro documentation, (because Microsoft has started to copy Apple's strategy of pretending documentation for their older products doesn't exist) we can break it down:
REPLACEis like SQL'sUPDATEorMERGE.The
ALLinREPLACE ALLmeans that all records in the table should be processed.WITH "N/A"means"N/A"is the new string/text value to store inColumn1.FORdenotes the start of the row predicate (which seems silly asALLis also a row predicate, kinda).Column2 = "Some string value" = .f.is the actual predicate expression.=and==: the==operator is specifically for exact text equality, while=has looser rules for determining equivalence..F.(or.f.) is a literalfalsevalue, and.T.(or.t.) is a literaltruevalue.x = y = false(rather than( x = y ) = falseorx = ( y = false )- I couldn't find any authoritative documentation re: FoxPro's operator associativity, but from the context it's clear the intent is( Column2 = "Some string value" ) = false- which could have just been written asFOR Column2 <> "Some string value".So this
REPLACE ALLstatement will:Column2is not equal to"Some string value"Column1 = "N/A".The equivalent T-SQL for SQL Server would be:
UPDATE(andMERGE, if you dare) DML statements do have a lot more functionality than FoxPro had - for example, consider using theOUTPUTclause to return the actually changed data to the client or into a table without needing anotherSELECT- andMERGElets you doUPDATE,INSERT, andDELETEat the same time in a single statement (with caveats) - so my point is that I think you should consider using this opportunity to explore how you can actively improve your product/project's codebase and functionality/features while you do this VFP-to-MSSQL porting work.Update: Better docs
I found a copy of the Visual FoxPro documentation file (
.chm) from the VFP9 CD and I've uploaded it to the Internet Archive if anyone would like unadulterated VFP docs, as the unofficial mirror I linked to has clearly been (at least) aesthetically compromised...It's here:https://archive.org/details/dv_foxhelp the
dv_foxhelp.chmfile should have a SHA-256 hash ofABAA86E7623BB00E8BD9323CF2D8E162013598E35D9492557A3DDD1C2CF13E79.On Windows 10 you'll need to fiddle with CHM/IE settings otherwise it'll display only a white page: