I'm trying to create a query in progress DB that gets the name portion off the email address. This is what I have so far:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, CHARINDEX('#', "PUB"."NAME"."INTERNET-ADDRESS") ) as Name
However, I'm getting a syntax error around the CHARINDEX(...
I'm not a progress guy and knowing SQL is just enough to get me into trouble...
Do you see the error in my ways?
Try this:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, INSTR("PUB"."NAME"."INTERNET-ADDRESS",'#') ).
Here you have the entire suite of documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview
Related
I have this query :
INSERT INTO lytnobjects.devices (id,idedge,uniqueref,constructeur,ipaddress,macaddress,
hostname,devicetype,isfirewall,isvisible,iscorporate,
ishub,osname,osversion,datecreation,lasttrafic,
hourtrafic,daytrafic,monthtrafic)
VALUES ('e1e455e98b6ed0037a58d0c1f5dc245a',3183,'TODO','TODO','192.168.143.49',
'b0:0c:d1:bb:36:1c','HPBB361C','Other',False,False,False,False,'','',
'2021-10-29T00:58:53.709','2021-01-01T00:00:00','0/0','0/0','0/0')
When I execute the query using python 3.9 and psycopg2_binary (PostgreSQL), I get an error :
unterminated quoted string at or near "'HPBB361C"
conn is the opened connection to the database (AWS RDS PostgreSQL)
sql is a string with the query above
def SQLExec(conn,sql):
try: cur = conn.cursor()
cur.execute(sql)
except (Exception, psycopg2.DatabaseError) as error:
print("***** ERROR:",error)
cur.close()
If I execute the same request from pgAdmin, I get no error !
There is no missing quote as you can see in the query, and no reason to point an error at this place!
So, I have a string (sql) with the query ("INSERT ...")
I call execute from psycopg2, and get an error: unterminated quoted string at or near "'HPBB361C"
I copy/paste the same string into pgAdmin, and the query is executed with no error
The same string (query)
Any idea why I get an error from my python app?
I am looking for an answer since many hours, but find no explanation, and I don't know how to fix the problem (which doesn't exist for me)
Your help is very appreciated
Thank you
I finaly found the answer!
I build the sql query (string) using some variables coming from various sources, like Amazon S3 for instance.
I assumed that the variable was really a string, with nothing "bizarre" in it... But in fact, sometimes, the "string" was ended with a "\x00" char, that is not displayed, so the string looks just normal :-/
When I execute my query (string) with psycopg2, it receives the extra \x00 char, which ends the string at this place! This is why it says there is a missing quote
I put a trace in the code to display the .encode() version of my string, and it revealed the \x00 at the end. So now I "clean" all string variables used in my queries, just with myvariable.replace("\x00","")
And it works now. There is probably a more conventional way to fix this...
I hope it may help somebody sometime! ;-)
$shop=DB::table('shops')
->leftJoin('orderbookings',function($join)
{
$join->on('shops.id','=','orderbookings.shop_id');
$join->on('orderbookings.created_at','>=',DB::raw(date("Y-m-d",strtotime("now"))));
})
->select('shops.*')
->selectRaw('COUNT(orderbookings.id) as totalorder, SUM(orderbookings.grand_total) as gtotal')
->orderBy('shops.shop_name', 'asc')
->groupby('shops.id')
->paginate(10);
Above code working fine(But not giving total order and amount correct) and also gives result almost close to what I want,
But I am not able to give date format (Y-m-d H:i:s), it shows syntax error. I am using Laravel 5.2 version
Note: I want to give time as well with date to rectify result,
On giving [example: 2017-03-08 11:15:00] shows syntax error
working query in mysql
SELECT COUNT(orderbookings.id), SUM(orderbookings.grand_total), shops.shop_name FROMshopsLEFT JOIN orderbookings on orderbookings.shop_id = shops.id and orderbookings.created_at BETWEEN "2015-10-22 17:02:02" AND "2017-03-07 17:02:02" GROUP BY shops.id
But not able to to convert in eloquent
You should be able to do the following:
$join->on('orderbookings.created_at', '>=', date("Y-m-d"));
You don't need to use DB::raw, and leaving the second parameter null for date, assumes "now".
If this doesn't solve your issue, please post the exact error you're seeing.
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...
How do I run a query using a value from a textbox from a form I have? I know that there is another post here at Stackoverflow dealing with this issue but I found it to be insufficient for my needs.
I formated my textbox into Medium Date format with its default value being =Date(). However, when I pick up a date and open my report I get this error:
Runtime error 3071: Expression Too Complex
My where clause is this
WHERE
(
(AllInfo.DateOpened >= CDate([Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value))
)
and I am sure it is this code piece that is throwing the problem since when I take it out of the query the error message simply disappears.
Any ideas?
Try with:
(AllInfo.DateOpened >= DateValue([Forms]![Main Form]![WindowPrintOptions].[Form]!txtDateOpenedFrom))
)
Folks,
I got the problem. It was the "AllInfo" alias. It wasn't applicable at that escope inside the query. By changing the proper things, it was enough to write:
[Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value
Issue solved. Thank you all!
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).