MYSQL - insert a variable into a string - mysql

I have created 2 variables
SET #SG_Positivity = 1600000000000027;
SET #SG_Relationship = 1700000000000027;
I want to use these inside of a string in my INSERT
INSERT INTO `core`.`card_config` (`version`,`scoring_model_id`,`locale_id`,`card_type`,`config`,`company_interview_id`)
VALUES('1',#ScoreModelID,'1','TTC','{"'+#SG_Positivity+'":{"summary":Tailored, personalized care"'+#SG_Relationship+'":{"summary":Ability to move others to action',NULL);
When executing the statement, I get the following error
Warning Code : 1292 Truncated incorrect DOUBLE value: '{"'

INSERT INTO core.card_config (version,scoring_model_id,locale_id,card_type,config,company_interview_id)
VALUES('1',#ScoreModelID,'1','TTC','{""'+#SG_Positivity+'''":{"''summary":Tailored, personalized care"'+#SG_Relationship+'":{"summary":Ability to move others to action"',
NULL);
Try above solution if nothing work then refer refer this for more information

Related

How does one update an attribute and add a new attribute in a JSONB column in YugaByte DB?

I am trying YugaByte's Cassandra API (YCQL) and interested in using the JSONB data type extensions.
But I am having trouble both updating an attribute in an existing JSONB column as well as adding a new attribute to an existing JSONB column.
Is this supported in YugaByte? Here is what I tried:
Consider the following example whichhas have one row with a simple key and JSONB column.
cqlsh:k> CREATE TABLE T (key int PRIMARY KEY, value jsonb);
cqlsh:k> INSERT INTO T(key, value) VALUES(1, '{"author": "Charles", "title": "Hello World"}');
cqlsh:k> SELECT * FROM T;
key | value
-----+--------------------------------------------
1 | {"author":"Charles","title":"Hello World"}
(1 rows)
So far so good.
If I try to update an existing attribute inside the doc, I see the following error:
cqlsh:k> UPDATE T SET value->'author' = 'Bruce' WHERE key=1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="SQL error: \
Invalid Arguments. Corruption: JSON text is corrupt: Invalid value.
If I try to add a new attribute into an existing JSONB attribute, I get the following error;
cqlsh:k> UPDATE T SET value->'price' = '10' WHERE key=1;
InvalidRequest: Error from server: code=2200 [Invalid query] message="SQL error: \
Execution Error. Could not find member:
Is this supported, and if so what is the correct syntax?
When updating a string value you must enclose the new value in double quotes inside the single quotes. For example:
cqlsh:k> UPDATE T SET value->'author' = '"Bruce"' WHERE key=1;
cqlsh:k> SELECT * FROM T;
key | value
-----+------------------------------------------
1 | {"author":"Bruce","title":"Hello World"}
(1 rows)
Regarding the second question on ability to add new attributes:
For UPDATE, currently (as of 1.1) YugaByte DB allows updating specific attributes if that attribute/field already exists, but does not allow addition of new attributes into an existing JSONB column. If you need to the latter, you need to read the old value into the app, and write the new json in its entirety.

Error trying to add .jpg at the end of filename in mysql

I have an attribute in a table that goes 1, 2, 3, 4, 5, ..... Right now, I'm trying to add .jpg to the file name. That is, it should be 1.jpg, 2.jpg, 3.jpg, 4.jpg,....
I tried using that command:
UPDATE tbl_items set filename = CAST(itemID AS char(10)) + '.jpg'
I'm getting this error
1292 Truncated incorrect DOUBLE value: '.jpg'
Can anyone tell me what is wrong?
The plus operator isn't valid in MySQL for string concatenation. Instead, try using CONCAT():
UPDATE tbl_items
SET filename = CONCAT(CAST(itemID AS CHAR(10)), '.jpg')
Your current error is probably arising because MySQL assumes you are trying to do arithmetic with either side of the plus operator.

MySQL: Triggers leading to Error 1292 (truncated incorrect DOUBLE value) when inserting?

Can you help me resolve the error 'Truncated incorrect DOUBLE value' (Error Code 1292) in MySQL 6.3? I've searched for a solid hour and can't find a suitable answer in all the similar questions:
My task is to insert triggers into a database of movies. If someone tries to update an existing value or insert a new value into the schema 'made_money', then it is to be assured that the category falls into one of four base categories (see code). If it doesn't, default to "Action". I built and executed two triggers for this (because I don't know how to put UPDATE and INSERT into a single trigger):
delimiter //
CREATE TRIGGER movie_categories_A BEFORE UPDATE ON made_money
FOR EACH ROW
BEGIN
IF NEW.Category NOT IN ("Romantic", "Comedy", "Drama", "Action") THEN
SET NEW.Category = "Action";
END IF;
END;//
delimiter ;
delimiter //
CREATE TRIGGER movie_categories_B AFTER INSERT ON made_money
FOR EACH ROW
BEGIN
IF Category NOT IN ("Romantic", "Comedy", "Drama", "Action") THEN
SET Category = "Action";
END IF;
END;//
delimiter ;
Also, a new entry into 'log_data' has to be made when a new value is inserted into 'made_money', containing only the 'Movie' and 'Category' values.
delimiter //
CREATE TRIGGER condensed_test AFTER INSERT ON made_money
FOR EACH ROW
BEGIN
INSERT INTO log_data
SET Movie = NEW.Movie AND Category=NEW.Category;
END;//
delimiter ;
The three triggers all executed, although I'm not sure whether they are erroneous. Now my task is to insert a new entry into 'made_money':
INSERT INTO made_money (MOVIE,HOW_MUCH,DAY_OPENED,Category)
VALUES ('Iron Man', 1000000, '2008-05-02', 'ACTON');
I know that 'ACTON' is misspelled (I guess this is part of the exercise), yet unfortunately, this results in the following error:
Error Code: 1292. Truncated incorrect DOUBLE value: 'Iron Man'
The same happens if I spell 'Action' correctly. Please let me know if you have any ideas.
Best,
Jan
Try to change datatype for Movie, try by making it Text,
you can refer Similar issue
Please check the datatype 'made_money.Movie' and 'log_data.Movie'.
Please check the collation.

MySQL Error pls-00103

I am making a MySQLand getting an error I dont know how to fix it. What the function should be doing is asking the user for input, this input should be stored in the corresponding variables and return a variable. But when i try run the function I am getting errors on the lines that store the variables. I am quite new to mySQL so i might be doing something stupid. Any help will be great thank you
This is is the mysql function
create or replace FUNCTION AD_AGENCY_INFO(agency_id in agency_id%type)
RETURN agency_id
DECLARE
v_no_of_runs AD_AGENCY.NO_OF_AD_RUNS%TYPE = '&enter_number_of_Runs';
v_credit_worthy AD_AGENCY.CREDIT_WORTHY%TYPE = '&enter_credit_worthy';
v_available_slots AD_AGENCY.AVAILABLE_SLOTS%TYPE = '&enter_available_slots';
v_status AD_AGENCY.STATUS%TYPE = '&enter_status';
BEGIN
insert into ad_agency values (agency_id, v_no_of_runs, v_credit_worthy,v_available_slots, v_status);
insert into ad (agency_id) values (agency_id);
commit;
RETURN (agency_id));
END AD_AGENCY_INFO;
The error that i am getting is the following and is the same for lines 7,8,9
Error(6,45): PLS-00103: Encountered the symbol "=" when expecting one of the following: := ( ; not null range default character The symbol ":= was inserted before "=" to continue.
Try changing your declare statement(s) to be
v_no_of_runs AD_AGENCY.NO_OF_AD_RUNS%TYPE := '&enter_number_of_Runs'

Error:insert hierarchy values using storedprocedure

I'm getting this error when trying to run a query that inserts results into a table in sql.
im passing the table name as parameter,how to give the hierarchy value to the insert statement.
here is my code:
declare #pathhere hierarchyid
select #pathhere=Path from SectionDetails where Sectionid=#sectionid and SectionName=#sectionname and Batchid=#batchid and Deptid=#deptid and Schoolid=#schoolid
insert stmt:
set #sqlstmt = 'insert into '+#batch+'(StudentID, StudentName,SectionID,SectionName,BatchID,BatchName, DeptID,DeptName, SchoolID,Path)
values('''+#sectionid+''','''+#sectionname+''','''+#sectionid+''','''+#sectionname+''','''+#batchid+''','''+#batchname+''','''+ #deptid+''','''+#deptname+''', '''+#schoolid+''','+ CAST(#pathhere as hierarchyid)+')'
exec(#sqlstmt)
im getting error in this line:
'+ CAST(#pathhere as hierarchyid)+'
as Invalid operator for data type. Operator equals add, type equals hierarchyid.
can anyone pls help me out how to pass the hierarchy value
You're trying to create a string that can be executed as a statement. So you need to get your hierarchyid into nvarchar(max) instead.
try: #pathhere.ToString()