Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referencing variable cursor names and their fields
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01515685
Message ID:
01515742
Views:
53
>>>You do need it according to the original logic. (he was doing seek and replace).
>>
>>either one works the same for me, so i use the short one, are there any drawbacks of using it my way?
>>
>>
>>CREATE CURSOR cur (pk int autoinc, xvalue char(10), fkPlans int)
>>CREATE CURSOR pln (pk int autoinc, xvalue char(10))
>>
>>INSERT INTO cur (xvalue, fkPlans) VALUES ('', 2)
>>INSERT INTO cur (xvalue, fkPlans) VALUES ('', 4)
>>INSERT INTO cur (xvalue, fkPlans) VALUES ('', 6)
>>INSERT INTO cur (xvalue, fkPlans) VALUES ('', 8)
>>
>>INSERT INTO pln (xvalue) VALUES ('ONE')
>>INSERT INTO pln (xvalue) VALUES ('TWO')
>>INSERT INTO pln (xvalue) VALUES ('THREE')
>>INSERT INTO pln (xvalue) VALUES ('FOUR')
>>INSERT INTO pln (xvalue) VALUES ('FIVE')
>>INSERT INTO pln (xvalue) VALUES ('SIX')
>>INSERT INTO pln (xvalue) VALUES ('SEVEN')
>>
>>UPDATE cur SET xvalue = pln.xvalue from pln WHERE pln.pk = cur.fkplans
>>
>>* or
>>
>>UPDATE cur SET xvalue = pln.xvalue FROM pln INNER JOIN cur ON cur.fkPlans = pln.pk
>>
>>
>
>The first variation is not traditionally written and I'm not sure why it works. May be VFP somehow allows this type of join.


This type of join also work in SQL Server :-)
CREATE TABLE #cur (pk int IDENTITY(1,1), xvalue char(10), fkPlans int)
CREATE TABLE #pln (pk int IDENTITY(1,1), xvalue char(10))

INSERT INTO #cur (xvalue, fkPlans) VALUES ('', 2)
INSERT INTO #cur (xvalue, fkPlans) VALUES ('', 4)
INSERT INTO #cur (xvalue, fkPlans) VALUES ('', 6)
INSERT INTO #cur (xvalue, fkPlans) VALUES ('', 8)

INSERT INTO #pln (xvalue) VALUES ('ONE')
INSERT INTO #pln (xvalue) VALUES ('TWO')
INSERT INTO #pln (xvalue) VALUES ('THREE')
INSERT INTO #pln (xvalue) VALUES ('FOUR')
INSERT INTO #pln (xvalue) VALUES ('FIVE')
INSERT INTO #pln (xvalue) VALUES ('SIX')
INSERT INTO #pln (xvalue) VALUES ('SEVEN')

UPDATE #cur SET xvalue = #pln.xvalue
       from #pln
WHERE #pln.pk = #cur.fkplans

SELECT * FROM #cur

DROP TABLE #cur
DROP TABLE #pln 
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform