SQL - Datatypes varchar and varchar are incompatible in the modulo operator [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 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.

Related

Filter a column on Oracle SQL developer like '%+%' [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 month.
Improve this question
I want to display all the names in a table that contains the character '+' but it doesn't work on Oracle SQL developer, while the column contains names with '+'
Select *
from Table where NAME like '%+%';
==> I got an empty output
Example:
Could you help me please ?!
You can use this statement:
Select *
from Table where NAME like '%' || chr(43) || '%';
Thank you

MySQL CONCAT cannot concat more than 2 items [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 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.

What does = 0 mean in PATINDEX? [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 1 year ago.
Improve this question
The code should accept nicknames containing the characters a-z A-Z 0-9 _ - '
IF PATINDEX('%[^a-zA-Z0-9_-']%' , #nickname) = 0
RETURN 1;
From the first line of the documentation on PATINDEX:
Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.
The documentation should always be your first port of call if you don't understand what a function does, or what the value(s) it returns represent.

How to get exact result from charindex? [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
select *
from table_name
where charindex(dest_mail,'abc#mail.com') >0
In the above query dest_mail is a column, but there is another entry in the table, which is 'bc#mail.com'. When I try to execute the above query, I'm getting two results
1.abc#mail.com
2.bc#mail.com
How to get exact 'abc#mail.com'?
Have you considered =?
where dest_mail = 'abc#mail.com'
Also, charindex() is not very colloquial SQL for this purpose; = is a built-in standard operator (charindex() is not standard). And a bonus to = is that it allows the optimizer to take advantage of indexes and partitions.

best way of searching string in sql table column of type "nvarchar(max)" [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
i'm trying to search within a table like
which works fine and gives a result table.
Also works fine if i searched like
But if added a digit before "ND" like
set #n='2 ND'
the search doesn't yield a result.
can anybody help??
Thanks in advance
According to your image, you appear to have two spaces between the "2" and "nd". So start by trying:
set #n = '2 ND';
Next, the spaces may not be ASCII spaces. If the above doesn't work, try the following, in order:
set #n = '2%ND';
set #n = '2__ND';
set #n = '2_ND';
The first should definitely match. The second would match two characters. The third would match a single character. If you do find that spaces don't match but the wildcard does, you can investigate what characters are actually in the data.