best way of searching string in sql table column of type "nvarchar(max)" [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 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.

Related

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.

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.

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 - Multiple Replace [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 8 years ago.
Improve this question
what i try to do is a multiple replace of an variable string.
but the problem that nothing happend.
i canĀ“t figured out what is wrong in the code:
can someone give me hand with this pls?
here is the sql code:
SET #HTML = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(#EMAILBODY2SEND,
'#%LoginUser%#',#Name),
'#%Number%#',#Number),
'#%classification%#',#classification),
'#%Phone%#',#Phone,
'#%Date#',#Date)
Hope following query can make your life easier by not nesting too many parentheses.
SET #HTML = #EMAILBODY2SEND;
SELECT #HTML = REPLACE(#Html, P, R)
FROM (VALUES ('#%LoginUser%#',#Name),
('#%Number%#',#Number),
('#%classification%#',#classification),
('#%Phone%#',#Phone),
('#%Date#',#Date)
) AS T(P, R)