MySQL CONCAT cannot concat more than 2 items [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I am currently studying SQL and am completing Hackerrank Questions (this is the question). The question involves concatenating strings. However when I use CONCAT according to convention, i.e:
SELECT
CONCAT(NAME, '(', LEFT(Occupation,1), ')')
FROM
OCCUPATIONS;
I receive the following error:
> SQL0440N No authorized routine named "CONCAT" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
However, if I enter the following code:
SELECT
CONCAT(NAME, CONCAT(CONCAT('(', LEFT(Occupation,1)), ')'))
FROM
OCCUPATIONS;
The code runs correctly and I receive the following output:
Kristeen(S)
Maria(P)
Meera(P)
Naomi(P)
Priya(D)
I have tried to use escape characters to no avail. I am able to concatenate any of the two strings fine however when I attempt to join any more than that in the cone CONCAT function I am unable.
Is this an error with my code, or an error with the platform? I have reviewed other solutions online that is coded exactly like the first solution and they are able to submit.

The issue was that on Hackerrank I had not changed the language from DB2 to MySQL in the top right hand corner, the error I was receiving was because I was using MySQL syntax where it wasn't supported.

Related

Access SQL Syntax error - Unable to find the error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 days ago.
Improve this question
SELECT AgentData.AgentLoginID,AgentData.KPIName,Minimum.Indicator,Minimum.PMonth,Minimum.PYear,Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue,
Round(IIf([Minimum].[Indicator]='P',(IIf([Goal]=0,Null,[GoalValue]/[Goal]),IIf(([Minimum].[Indicator]='N' And ([Minimum].[Min]=0 Or [Minimum].[Min]=(format(0,"Percent")),Null,([Minimum].[Min]-[GoalValue]/[Minimum].[Min]),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
I have been trying to execute this code in access, but no success, i keep getting a syntax error, missing operator in expression, but unable to figure out what the issue is, so wondering if anyone could help, i get an error with the SQL statement marked in bold
SELECT AgentData.AgentLoginID, AgentData.KPIName, Minimum.Indicator, Minimum.PMonth, Minimum.PYear, Minimum.Min,
IIf(InStr([AgentData].[Goal],'%')>0,(Left([AgentData].[Goal],Len([AgentData].[Goal])-1)/100),[AgentData].[Goal]) AS Goal,
AgentData.Weightage,
Round(IIf(InStr([AgentData].GoalValue,'%')>0,(Left([AgentData].GoalValue,Len([AgentData].GoalValue)-1)/100),[AgentData].GoalValue),2) AS GoalValue, Round(IIf([Minimum].[Indicator]='P',IIf([Goal]=0,Null,[GoalValue]/[Goal]),
IIf(([Minimum].[Indicator]='N' And [Minimum].[Min]=0),Null,([Minimum].[Min]-[GoalValue])/[Minimum].[Min])),4) AS [Value],
Round([AgentData].Weightage*Value,4) AS Product
FROM Minimum INNER JOIN AgentData ON Minimum.KPIName = AgentData.KPIName;
The above query runs perfectly fine, but i get a snytax errors when i add the OR operator for Minimum.Min as i want it to exectue in two scenarios , one is when Minmum.min is 0 or when minimum.min = 0%

SQL - Datatypes varchar and varchar are incompatible in the modulo operator [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I have the following query that used to work but returns the error addressed on the title. The last line is indicated within the error.
UPDATE [dwh].[dbo].[opco_securty]
SET opco_general = REPLACE([dwh].[dbo].[opco_securty].opco_general, [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, '''')
FROM [dwh].[dbo].[opco_securty]
JOIN [MSTR_MD].[dbo].[v_OpcoGeneral_UserList]
ON [dbo].[opco_securty].opco_general LIKE CONCAT(''%'', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, ''%'');
Change this
ON [dbo].[opco_securty].opco_general LIKE CONCAT(''%'', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, ''%'');
To this
ON [dbo].[opco_securty].opco_general LIKE CONCAT('%', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, '%');
Because the goal is to concatinate the % character to the column. So that it creates a string that's usable by the LIKE.
But in MS Sql Server you escape a single quote with a single quote.
So the ''%'' is messing things up.
Because the % is seen as the modulus operator.

Postgres column doesn't exist error on update [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to run the query below but I am getting an error ERROR: column "test.pdf" does not exist . I dont know why I am getting this error. I search for various links on stackover but none solved my problem like this PostgreSQL query -- column does not exist, Postgres error updating column data. Please help me find the problem.
bill is a type string field in bills table.
update bills
set bill = "test.pdf"
where id=3;
Change the double quotes you have around test.pdf to single quotes.

SQL Server column select query behaving strangely [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
When I do a select * over the table, the column Qty & QtyPending show a value of 6. However explicitly selecting the column names shows different values. Can anyone shed some light as to why this behavior is occurring?
This is a legacy system and database used is SQL Server 2000. The column data types are smallint.
So I have explicitly updated QtyPending to 6 using an Update query. This column now shows correct value.
Also added locstockid to the query, column Qty still shows different values.
Whatever I see in the image provided both the query have different LocStockId which means they can have different values
First :
LocStockId = 152319
Second :
LocStockId = 153219
I think you have mistyped.

SQL LIKE doesn't find obvious matches [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.