Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with PostgreSQL Query
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01429771
Message ID:
01429772
Views:
53
>Dear all
>I am trying to execute the following query in postgresql, but keep getting errors ("error near group by"). Tried to run it in pgadmin's query tool, and got different errors ( like IIF not recognized ). Can anyone help me "translate" the sql from vfp to postgre?
>Table name in postgre: weblog
>Fields: agent C(4), function varchar(20), xmlstr text
>
>lcStr = [select weblog.agent, ]+;
>[sum(iif(weblog.function="GetCars" or "GETCARS"$weblog.xmlstr,1,0)) as RateRequests,]+;
>[sum(iif(weblog.function="CarRes" or "CARRES"$weblog.xmlstr,1,0)) as Bookings ]+;
>[from weblog order by weblog.agent group by weblog.agent]
>=sqlexec( oConnection,  lcStr, "TempCursor" )
>
>TIA
>Jaime

Don't know if the SQL Server T-SQL syntax has something common with postgre, but here the SQL Server version:
TEXT TO lcStr NOSHOW
     select weblog.agent,
            SUM(CASE WHEN weblog.function = 'GetCars' OR
                         CHARINDEX('GETCARS', weblog.xmlstr) > 0
                     THEN 1 
                     ELSE 0 END) as RateRequests,
            SUM(CASE WHEN weblog.function = 'CarRes' OR
                         CHARINDEX('CarRes', weblog.xmlstr) > 0
                     THEN 1 
                     ELSE 0 END) as Bookings
     from weblog
     group by weblog.agent --- Group must be before ORDER BY
     order by weblog.agent
ENDTEXT
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