What does = 0 mean in PATINDEX? [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 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.

Related

Presto: parse an entire column from a string to a date [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 days ago.
Improve this question
Current code I have is as follows:
select date_parse(column_name,'%Y-%m-%d %H:%i:%s')
This is the error I receive:
Error running query: line 1:19: Column "column_name" cannot be
resolved
I know that the format of the date I inserted is correct because I tested it with a value I have in the database and it returned the correct date value. It may be related to several records having no value in the column specified? Not exactly sure how I would account for that
I'm expecting the code to turn the entire column from a string into a date

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.

Subtract Values in Two Ranges VBA [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 am trying to write VBA code to subtract column A from column B. I want it to take the first cell in each range and do the math then output the resulting value in column C.
i.e. the output should look like:
Sub FOO()
[C1:C6] = [B1:B6 - A1:A6]
End Sub

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.

Give an Alias to a column I've casted as a date [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 7 years ago.
Improve this question
Basically I'm selecting all the rows from a table and stripping the time portion of the date using
CAST(CREATE_DATE AS DATE)
but my results give me the rows I need but the column is unnamed.
How do I give the column a name?
Like this:
Cast(create_date as date) as [Column Name Here]
You can omit the [] if you are not using spaces or reserved words in your column name (which is good practice anyway).