Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP SQL Syntax - Tuesday BrainFreeze
Message
De
10/07/2007 13:26:41
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01238981
Message ID:
01238997
Vues:
9
Thanks all! :o)


>>All fields are character.
>>
>>Table1 fields:
>>
>>aid
>>aagcy
>>adescriptn
>>
>>Table2 fields:
>>
>>bidv (same value as aid in table1)
>>bname
>>bvalue
>>
>>I want to join the above two tables and do the following:
>>
>>1. Create a single record for every distinct or unique aid record in table1 whether or not a match exists in table2.
>>2. Include the fields: table1.aid, table1.aagcy, table2.bvalue
>>3. If there is no matching record in table2, then I want to populate the bvalue field in the joined cursor with an empty string value ''.
>>
>>I am stuck on a simple sql statement which amazes me. I just can't concentrate today :o( Maybe it was the only 2 hours of sleep I got last night? :o)
>
>Assuming aID is unique in table1
>
>select T1.*, nvl(S1.bname, space(10)) as bName, ;
>NVL(S1.bValue,space(10)) as bValue from Table1 T1 ;
>left join (select bID, max(bName) as bName, max(bValue) as bValue ;
>group by 1 from Table1) S1 on T1.aID = S1.bID
>
>If we may have duplicates in Table2 on bID. Otherwise just a left join of table1 and table2
>
>Instead of space(10) it should be number of spaces for the field length.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform