Subsonic help, how to list only the first record - select

Hi I'm doing a little report using subsonic I'm pretty noob And I can't figure how to list only the first record in my report I'm doing something like:
new Select("id,Name,place,group").From(User.Schema)
.InnerJoin(Profile.Schema)
.InnerJoin(userGroup.Schema)
.Where("place")
.IsEqualTo("insomeplace")
.ExecuteReader();
result:
093007 Joe doe insomeplace S2A
093007 Joe doe insomeplace S2A
093007 Joe doe insomeplace S2A
093007 Joe doe insomeplace S2A
I have try to new Select("bla bla").Distinct() new Select("bla bla").Top("1") but none of those appear to work... so what I can do??? any ideas???
When used Top("1") I got a error saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1user.id, user.Name, Place, Place
FROM user
' at line 1"
I'm using subsonic 2.x
thanks in advance

I'm assuming from the reference in your question that you are using MySql. I'm afraid that I don't know much about MySql, but the following may be helpful:
I can assure you that .Top("1") certainly works in SubSonic 2.x against SQL Server.
Can you find an equivalent to SQL Server's Profiler for MySql to see what SQL code is being sent to the database?
TOP 1 isn't valid SQL in MySql, instead you need to use the LIMIT clause - http://dev.mysql.com/doc/refman/5.0/en/select.html

quit!!!! I proffered use of
string sqlString = "Select * ...";
new InlineQuery().ExecuteReader(sqlString);

You can use the Paged(...) method:
new Select("id,Name,place,group").From(User.Schema)
.InnerJoin(Profile.Schema)
.InnerJoin(userGroup.Schema)
.Where("place")
.Paged(1, 1)
.IsEqualTo("insomeplace")
.ExecuteReader();
I'm not 100% percent sure if you have to use Paged(1,1) or Paged(0,1), try both.

Another way to do this would be to use .ExecuteSingle(), which would return only the first result. The downside of this is that the database would actually return all rows of the query (SubSonic simply discards anything but the first record).

Related

how to use for each loop in Progress?

Basically i'm trying to do a simple join. I'm a beginner in progress and even if i'm reading always the same things... my problem still unresolved ! :'(
I'm using unixodbc to communicate with my base and this is working like a charm when i'm using simple command like : SELECT * from PUB."Art"
I understood I have to do something who looks like that to join 2 tables :
FOR EACH PUB."Art" WHERE (PUB."Art".IdArt = 16969) ,
EACH PUB."ArtDet" WHERE (PUB."ArtDet".IdArt = PUB."Art".IdArt)
END
But this only return me [ISQL]ERROR: Could not SQLPrepare
I then try to simplify the thing with :
for each PUB."Art": display PUB."Art".IdArt end.
I try to put colon (or not) after the for each loop, using point / comma etc... but I never use the right syntax apparently... or I'm missing a thing to execute this command !
Is anyone can advice me ?
Thx a lot !
You appear to mixing SQL and 4GL syntax.
"FOR EACH" is 4GL. The SQL equivalent is "SELECT".
(If you are using 4GL you do not need then "PUB" prefix and quoting table and field names will not work.)
To do a join with SQL (or the 4GL) use a "," between the table names. For SQL your syntax would look something like:
SELECT * from PUB."Art", PUB."ArtDet"
Gory details regarding WHERE clauses, SQL INNER & OUTER joins etc. can be found in the online documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview
You will want to navigate to your specific release and then find the "SQL" guide.

Syntax error on DB2 XMLELEMENT

I get this error when trying out this command in the BIRT Classic Models sample database in Data Studio
select xmlelement(name "custno", customers.customernumber) from customers
Syntax error: Encountered "\"custno\"" at line 1, column 24.
I do not know how to correct it.
Thanks.
I'm not familiar with db2, but according to this your statement looks quite alrigth (although I'd place an alias to name this field...)
But this
Syntax error: Encountered "\"custno\"" at line 1, column 24.
seems to be a quite clear hint, that your error is connected to the NAME of the element.
I'm pretty sure, that this statement was created on string level.
Did you try to escape the "-characters with \"?
The SQL reaching the engine might look like
select xmlelement(name \"custno\", customers.customernumber) from customers
or
select xmlelement(name "\"custno"\", customers.customernumber) from customers
... which is wrong of course...
But to be honest: just guessing...

GreenPlum Substring - Getting part of a long text

say I have a long URL
xyz = 'www.google.com/xyz?para1=value1&para2=value2&para3=value3....'
I am trying to get the 'para1' out of this long URL
So, I have
select TRIM(Leading '?' from Substring(xyz from '%#"?%=#"%' for '#'))
The answer I get for this particular statement is
para1=value1&para2=value2&para3=
How can I get just 'para1' using the select statement above (or any other similar method?)
I am using Greenplum (as mentioned in the topic heading)
Since you apparently have the regexp_ functions (I didn't think Greenplum supported them) use:
select (regexp_matches(
'www.google.com/xyz?para1=value1&para2=value2&para3=value3....',
'\?([^&]+)='
))[1];

T-SQL SELECT Statment to Exclude Text Between ( And ) Without Update or Variables

I'm wondering if this is possible, I have a messy set of first name data to work with, and it's shared by other applications so I don't want to run any update statements. But the data will sometime include an AKA such as:
Robert (AKA Bob)
And I am trying to get a clean data where it just says "Robert".
One way I thought of is to use a temp table then CHARINDEX for ( and ) then REPLACE what's between ( and ). This seems like a long winded way to do this.
Is there a smarter way?
EDIT: More examples of the data hell. Sometimes the parenthesis comes in the front or mixed up such as:
(Bill) William
Richard (Dick) Jr.
Untested:
FirstName = case when charindex('(AKA', FirstName) = 0
then FirstName
else substring(FirstName, 1, charindex('(AKA', FirstName)) end
If the noisy string pattern is unpredictable, better to use SQL CLR TVF(table value function), utilize C# code regex. Taking an xml as input parameter, which includes data you need to process, return a table with data processed.
Pieter got the ball rolling for me! Thank you for getting me started on the right track!
SELECT
CASE WHEN FirstName like '%)%'
THEN REPLACE(FirstName,
SUBSTRING(FirstName,CHARINDEX('(',FirstName),CHARINDEX(')',FirstName)-CHARINDEX('(',FirstName)+1),'')
ELSE FirstName END

Foursquare API nearByVenue service issue

Using Foursquare api "Venue" service.. i am parsing nearByVenue details like shop, restaurant etc.
Suppose as an example i am getting following link:
https://api.foursquare.com/v1/venues.json?geolat=40.562362&geolong=-111.938689
Issue is I am getting only 10 nearbyDetails.. suppose I am standing in New York there should be number of venue details.. why I am getting only 10 details only ?
Is there any other service or i am following wrong approach to use it?
Thanks
Add l=n where n is your limit in query string. The default limit is set to 30.
https://api.foursquare.com/v1/venues.json?geolat=40.562362&geolong=-111.938689&l=10
https://api.foursquare.com/v1/venues.xml?geolat=40.562362&geolong=-111.938689&l=50&q=coffee
You can change the value of l="no of result" parameter.
And also if you want to search for particular keyword like ATM, Coffee
then you can add the parameter q and add it's value like q="atm", q="coffee", etc.
hope it will be helpful to you.