on 5/30/01 23:12, Steven at srt /at/ bigpond D.O.T net.au wrote:
> Hi Ruslan, > > I have a table with fields A, B, C and D. > > I want to search through the table for records where D=foo. > > However, depending on the value of the field C for the matching records, I > want to retrieve either the field A or B for that record, according to the > rule: > > If C=0 then > i want to retrieve field A > else > i want to retrieve field B > end > > Can I do this conditional selection within the sql statement, something > like this?: > Select (A if C=0 else B) from Table where D=foo. > > I think this might be possible using the Control flow function > IF( exp1, exp2, exp3 ) that I see in the valentina sql documentation, but > I'm not sure? > > Something like > "Select IF(C=0,A,B) from Table where D=foo"???
Yes you need to use this IF( exp1, exp2, exp3 ) function.
but you can not use it directly in SQL query. You must at first define a BaseObject Method using it, for example
D = "if( C = 0, A, B)"
Now in SQL you can do:
SELECT D FROM T Where ...
> The idea being that the resulting cursor will already have the correct > field that I need for each record, rather than having to retrieve both > fields and then testing each record in the cursor in a WS loop to select > the appropriate field for the record.
-- Best regards, Ruslan Zasukhin
------------------------- Paradigma.
e-mail: ruslan@paradigmasoft.com web : http://www.paradigmasoft.com
To subscribe to the Valentina mail list send a letter to valentina-on /at/ lists D.O.T macserve.net
------------------------------------------------------------- The Valentina mailing list is brought to you by MacServe.net For info on lists services, see http://www.macserve.net/lists.html ©2001 Ruslan Zasukhin |