error when selecting multiple tables - mysql

SELECT pc_info_tbl.`serial_id` "Serial Number",
pc_info_tbl.`replacement_warranty_date` "Replacement Warranty",
pc_info_tbl.`service_warranty_date` "Service Warranty",
personel_tbl.`fname` "First Name",
personel_tbl.`mname` "Middle Name",
personel_tbl.`lname` "Last Name",
repair_records_tbl.`repair_date` "Repair Date",
repair_records_tbl.`service_slip_no` "Service Slip Number",
repair_records_tbl.`itmd_personel_id` "ITMD Personnel",
repair_records_tbl.`notes` "Notes"
FROM repair_records_tbl,
itmd_personel_tbl,
pc_info_tbl,
personel_tbl
WHERE repair_records_tbl.`personel_id` = personel_tbl.`personel_id`,
repair_records_tbl.`serial_id` = pc_info_tbl.`serial_id`,
repair_records_tbl.`itmd_personel_id` = itmd_personel_tbl.`itmd_personel_id`;
I want to select multiple tables, but I get error some where on repair_records_tbl.`serial_id` = pc_info_tbl.`serial_id`, repair_records_tbl.`i
Error Code: 1064
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 ' repair_records_tbl.serial_id = pc_info_tbl.serial_id, repair_records_tbl.`i' at line 5
anyone can teach me the right syntax?

Your where clause has a syntax error. May be you want to use AND
Change:
WHERE repair_records_tbl.`personel_id` = personel_tbl.`personel_id`,
repair_records_tbl.`serial_id` = pc_info_tbl.`serial_id`,
repair_records_tbl.`itmd_personel_id` = itmd_personel_tbl.`itmd_personel_id`;
to:
WHERE
repair_records_tbl.`personel_id` = personel_tbl.`personel_id`
and repair_records_tbl.`serial_id` = pc_info_tbl.`serial_id`
and repair_records_tbl.`itmd_personel_id` = itmd_personel_tbl.`itmd_personel_id`;

You separate column names while doing the select by comma but use AND/OR between the two where clauses and not separate them by comma:
SELECT pc_info_tbl.`serial_id` "Serial Number", pc_info_tbl.`replacement_warranty_date` "Replacement Warranty", pc_info_tbl.`service_warranty_date` "Service Warranty", personel_tbl.`fname` "First Name", personel_tbl.`mname` "Middle Name", personel_tbl.`lname` "Last Name", repair_records_tbl.`repair_date` "Repair Date", repair_records_tbl.`service_slip_no` "Service Slip Number", repair_records_tbl.`itmd_personel_id` "ITMD Personnel", repair_records_tbl.`notes` "Notes"
FROM repair_records_tbl, itmd_personel_tbl, pc_info_tbl, personel_tbl
WHERE repair_records_tbl.`personel_id` = personel_tbl.`personel_id`
AND repair_records_tbl.`serial_id` = pc_info_tbl.`serial_id`
AND repair_records_tbl.`itmd_personel_id` = itmd_personel_tbl.`itmd_personel_id`;

Related

exiting strategy "long" when "short entry" triggered, hit "stop loss" and "hit target"

Sorry for my bad English(English is not my first language)
I want to execute , exit the "long" and enter the "short" at the same time when "short entry" is trigged. I tried below code.It only exit when hit Target and Stoploss.It doesn't exit the "long" at "short entry" and doesn't exit the "short" at "long entry".
Much appreciate any help!
strategy.entry (id="Long", long=strategy.long, when = ValidLong, comment ="Long" )
strategy.entry (id="Short", long=strategy.short, when=ValidShort, comment="Short" )
strategy.exit(id = "Long Exit", from_entry = "Long", limit =Target , loss = Stoploss , when = strategy.position_size > 0)
strategy.exit(id = "Short Exit", from_entry = "Short", limit = Target, loss = Stoploss, when = strategy.position_size < 0 )

Clean JSON column from bad data in Snowflake

I have a table in Snowflake with many columns, and one of those columns is JSON column called RECORD (check attached pic), so JSON column has multiple columns in it and some of these columns has bad data like ( // , * or \\ ) and I would like to create function in snowflake to clean up this JSON column from bad data, my JSON is below
{
"F000 //Start Date": "3/3/2016 21:04",
"F001 End Date": "3/3/2016 23:20",
"F002 *Response Type//": "IP Address",
"F003 IP Address": "166.170.14.93",
"F004 SurveyName\\": "6 Month",
}
A simple way might be to implement a Javascript UDF that returns the cleaned up JSON, like this.
CREATE OR REPLACE FUNCTION clean(record variant)
RETURNS variant
LANGUAGE JAVASCRIPT
AS $$
cleaned = {}
for (const property in RECORD) {
cleaned[property.replace(/\/\/|\\|\*/g, '')] = RECORD[property]
}
return cleaned
$$;
with tbl as (select parse_json($1) record from values ('{
"F000 //Start Date": "3/3/2016 21:04",
"F001 End Date": "3/3/2016 23:20",
"F002 *Response Type//": "IP Address",
"F003 IP Address": "166.170.14.93",
"F004 SurveyName\\\\": "6 Month",
}'))
select clean(record) from tbl;
{
"F000 Start Date": "3/3/2016 21:04",
"F001 End Date": "3/3/2016 23:20",
"F002 Response Type": "IP Address",
"F003 IP Address": "166.170.14.93",
"F004 SurveyName": "6 Month"
}

Error While formating a mysql statement which includes a regular expression

Am trying to retrieve data from a Mysql table i get an error while applying string formatting techniques
First try, results an error
1.service= "Dynamic value"
st="SELECT Name FROM servicetable WHERE hsubservices={0} and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}'".format(service)
The error which occured here is Index out of range for tuple , yes i get it the '{}' in regular expression are being considered as values of tuple
service="Dynamic Value"
error=mysql.connector.errors.ProgrammingError: 1064 (42000): 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 'Value and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}''
st="SELECT DoctorsName FROM dev_healthservices WHERE hsubservices= %s and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}'"%(service)
mydb=mysql.connector.connect(
host = "",
user = "",
passwd = "",
database = ""
)
mycursor=mydb.cursor()
mycursor.execute(st)

I want to know good syntax for mysql pdo json

I haven't found the good syntax to update my table on mysql using json_set.
Would you give me some help? I want to update and know the good syntax for this query.
public function mkjson()
{
$friends = '"pachou", "eric", "francis"';
$tagfriendsjson = json_encode($friends);
try
{
include('connect.ini');
}
catch (Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$ver = 'SELECT * FROM tagusers WHERE tag_users_id="'.$_SESSION['tagusersid'].'"';
$ask = $bdd->query($ver);
$ans = $ask->fetch();
if (empty($ans['tag_friends']))
{
$req = $bdd->prepare('UPDATE tagusers SET = {"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"} WHERE tag_users_id="'.$_SESSION['tagusersid'].'" ');
$req->execute();
}
else
{
}
return true;
}
: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 '= {"4": "Henry"} WHERE tag_users_id="2"' at line 1 in /var/www/tagmeyou.com/php/class.Friendlist.php:34 Stack trace: #0 /var/www/tagmeyou.com/php/class.Friendlist.php(34): PDOStatement->execute() #1 /var/www/tagmeyou.com/fr/vues/body/inputtag.php(23): Friendlist->mkjson() #2 /var/www/tagmeyou.com/fr/vues/body/bodytagscreen.php(10): include('/var/www/tagmey...') #3 /var/www/tagmeyou.com/fr/vues/tagscreen.php(34): include('/var/www/tagmey...') #4 {main} thrown in
There are two errors in this query:
UPDATE tagusers SET = {"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"} WHERE tag_users_id="'.$_SESSION['tagusersid'].'"
Firstly, there is no column name being set (between SET and =). Secondly the JSON should be in single quotes. Try changing that line to
$req = $bdd->prepare('UPDATE tagusers SET colname = \'"1": "pachou", "2": "eric", "3": "francis", "4": "Henry"}\' WHERE tag_users_id="'.$_SESSION['tagusersid'].'" ');
Where colname is the column you want to store the JSON in.

VBA Parse Nested JSON

VBA Noob here. Please excuse any gaps in terminology etc.
I am trying to parse a JSON file into a spreadsheet using VBA-JSON v2.2.3 (c) Tim Hall - https://github.com/VBA-tools/VBA-JSON.
The JSON file looks like this:
{
"site": "{5BEC7C29-FF95-4ECC-9314-064B52618EEE}",
"from": "2017-01-16",
"to": "2017-01-22",
"timeSheet": [
{
"date": "2017-01-16",
"person": "{E2A5FDE1-33F8-43CA-A01D-5DD4A3A5E23A}",
"personName": "James Smith",
"company": "{B03CF7B3-0BE9-44B4-8E55-47782FDD87C0}",
"companyName": "Acme Company Ltd",
"minutes": "510",
"activities": [
{
"name": "Training",
"code": "TR",
"minutes": "240"
},
{
"name": "Administration",
"code": "AD",
"minutes": "150"
},
{
"name": "Payroll",
"code": "PR",
"minutes": "60"
},
{
"name": "Meal break",
"code": "",
"minutes": "60"
}
]
}
]
}
There may be any number of 'timeSheet' records, as well as any number of 'Activities' within each timeSheet including zero.
I want a row in the spreadsheet for each activity, with the name and other data outputted next to that days activities. Essentially showing a log of all the activities done, for how long and by who. To complicate issues, I still need the name etc outputting even if no activities are recorded. I will then fill with 'unallocated time' or something similar.
Below is as far as I have got (abridged), with an updated count of the activities occurring every loop. This feels a little hacky and doesn't give me what I am looking for, often adding additional rows and sometimes missing activities entirely.
i = 2
j = 1
activCount = CStr(JSON("timeSheet")(1)("activities").Count)
If activCount = 0 Then activCount = 1
ws.Cells(i, 1) = JSON("site")
ws.Cells(i, 2) = JSON("from")
ws.Cells(i, 3) = JSON("to")
For Each item In JSON("timeSheet")
For j = 1 To activCount
On Error Resume Next
ws.Cells(i, 4) = item("date")
ws.Cells(i, 5) = item("personName")
ws.Cells(i, 6) = item("companyName")
ws.Cells(i, 7) = item("minutes")
ws.Cells(i, 9) = item("activities")(j)("name")
ws.Cells(i, 10) = item("activities")(j)("code")
ws.Cells(i, 11) = item("activities")(j)("minutes")
activCount = CStr(JSON("timeSheet")(i)("activities").Count)
If activCount = 0 Then activCount = 1
i = i + 1
Next
Next
Can someone help? I have run out of ideas and have been working it for some time! Thank you. :)
This worked fine for me:
Sub TestJson2()
Dim ts, act
Dim Json As Object, c As Range
'reading json from a worksheet cell...
Set Json = JsonConverter.ParseJson(Range("A3").Value)
Set c = ActiveSheet.Range("C5")
'loop over timesheets
For Each ts In Json("timeSheet")
'loop over timesheet activities
For Each act In ts("activities")
c.Resize(1, 11).Value = Array(Json("site"), Json("from"), Json("to"), _
ts("date"), ts("personName"), ts("companyName"), _
ts("minutes"), act("name"), act("code"), _
act("minutes"))
Set c = c.Offset(1, 0)
Next act
Next ts
End Sub