patternsqlMinor
INSERT/UPDATE in same query from previous SELECT with some singularities
Viewed 0 times
samepreviousinsertupdatewithquerysingularitiessomeselectfrom
Problem
I'm trying to perform a
[Err] 1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MariaDB server version for the right syntax
to use near 'from veeva.
line 1
and I'm not sure what is wrong on the query, any advice?
INSERT|UPDATE by selecting data from another DB and this is what I have so far:INSERT INTO pdone.reps
(veeva_rep_id,display_name,username,`first`,`last`,email)
SELECT Id, CONCAT(UCASE(LEFT(firstname, 1)),UCASE(LEFT(lastname, 1)),username, firstname, lastname, email
FROM veeva.`user`
WHERE Id = "00580000003UB5VAAW"- First problem, I got this error:
[Err] 1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MariaDB server version for the right syntax
to use near 'from veeva.
user WHERE Id = "00580000003UB5VAAW"' atline 1
and I'm not sure what is wrong on the query, any advice?
firstnamecould be JOHN or John or jOhn or any and I want to normalize as John, isUCASE(LEFT(firstname, 1)fine for this? The same apply tolastname
- If
firstnameis JOHN andlastnameis DOE thenusernameshould beJohn Doewith a space between them, is myCONCATENATEright?
- I should insert some statics fields like one URL or just
VEEVAhow I can do that? Values are not present on the query shown here but is just add two more columns to the insertavatar_urlandrep_type
- I am planning to add
ON DUPLICATE KEY UPDATEbut can be possible to add a restriction based on a column? Lets said UPDATE only if now >lastSyncDate?
Solution
Insert query:
It will print Only first letter capital from both First & Last name.
INSERT INTO pdone.reps (veeva_rep_id,display_name,username,first,last,email,avatar_url,rep_type)
SELECT
Id,
CONCAT(UCASE(MID(firstname,1,1)),LCASE(MID(firstname,2)),' ',UCASE(MID(lastname,1,1)),LCASE(MID(lastname,2))),
username,
firstname,
lastname,
email,
'www.some_static_url.com',
'1'
FROM veeva.user
WHERE Id = "00580000003UB5VAAW"It will print Only first letter capital from both First & Last name.
Code Snippets
INSERT INTO pdone.reps (veeva_rep_id,display_name,username,first,last,email,avatar_url,rep_type)
SELECT
Id,
CONCAT(UCASE(MID(firstname,1,1)),LCASE(MID(firstname,2)),' ',UCASE(MID(lastname,1,1)),LCASE(MID(lastname,2))),
username,
firstname,
lastname,
email,
'www.some_static_url.com',
'1'
FROM veeva.user
WHERE Id = "00580000003UB5VAAW"Context
StackExchange Database Administrators Q#105386, answer score: 4
Revisions (0)
No revisions yet.