How to find value that have some charcter in third position? [closed] - sql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I Couldn't find the value that has 'r' in the third position using LIKE operation in SQL.
could anyone help me, please?

I think it would be better to write something like this.
SELECT <column>, FROM <table> WHERE <condition> LIKE "__r%";
EDIT:
This is tested and functional for SQL Server and Oracle DBMSs.

SELECT * FROM <table> WHERE substring(<column>,3,1) = 'r'
Try this. This is using SQL Server which will yield the result you are looking for.

You want to get the r from 'scr' with position 3
Try this
SELECT * FROM Customers
WHERE CustomerName LIKE '__r%';
position is count of _.

Related

Comparison with '{0}' in SQL SELECT [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I have to take over old colleague's code and trying to understand this one SQL statement like below:
SELECT * FROM my_table WHERE date_key = '{0}'
Column date_keycontains int values such as 20220712, 20220120, etc.
The first guess is that SELECT statement filters for rows with 0 value in column date_key. However, when running that line of code, I receive this error :
SQL Error [100038] [22018]: Numeric value '{0}' is not recognized
What exactly does that line of code do?
That looks like a placeholder, replaced with an actual value in code when calling the query.
See similar What is {0},{1},{2},{3} in the SQL query

Do I need to create sample tables with data always to recreate the issue in questions? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
As I am a beginner to stackoverflow community, Can someone help me with following questions?
What are the possible ways to write queries and give answers
to stackoverflow questions?
Do I need to create databases with sample data locally from
scratch to answer them?
Is there any online tools that can
write queries with dummy data help
to answer the questions quickly?
Really appreciate your answers on this.
I believe you are looking for something like this
What are the possible ways to create code samples and give answers to stackoverflow questions?
https://dbfiddle.uk/
http://sqlfiddle.com/
https://www.db-fiddle.com/
Here you can create objects, create data and write code simulate "the answer" to some question.
Do I need to create local projects from scratch to answer them?
I am not sure what are you asking here but NO.
Is there any online tools that can create code samples with dummy data (in case of a SQL question) help to answer the questions quickly?
https://generatedata.com/
https://www.onlinedatagenerator.com/
This question and also possible answers are likely to some part opinion based (and this is something which should be avoided on Stackoverflow).
But some things to answer your question should be generally correct and not opinion based. So whenever you ask a SQL question, take care of following points:
Describe your issue as most precise and clear as possible, but avoid to add unnecessary or confusing information
Tag the DB you are using
Always show the sample input and expected outcome
Show what you tried to solve your issue (in best case, you already created a query that is almost correct) and explain why it's not working yet.
If possible, provide a DB fiddle to allow people to replicate your issue.
There will be further points (maybe someone will provide another answer or comment this one), so overall you can just ask yourself "Have I done everything possible to make it possible that people can understand my issue and provide a possible solution?" and make sure your question is asked in a way which answers this question with "Yes!".
Let's make a very simple example:
Your sample input is:
Table yourtable
column1
column2
1
2
2
2
3
4
0
10
And you want to find this outcome:
column1
column2
2
2
0
10
The rows you want to receive should have identic values in column1 and column2 OR column1 = 0.
Now you also tell us that you tried this query:
SELECT column1, column2
FROM yourtable
WHERE column1 = column2
AND column1 = 0;
But this query doesn't find any rows. Remember this is a really simple example and of course, you would have found the reason. But since we just want to illustrate the way of asking questions, now you have already shown us sample input, expected outcome and your failing idea how to get this result.
Now, you could also add a fiddle example with all this information.
db<>fiddle
Well, perfect! Now people can easily understand and replicate your issue and just need to think about a solution and check this solution using the fiddle you've shown. And then you will likely get a correct answer in a short time and don't have to ask plenty of questions because your question was too unclear.
So in this simple case, someone would tell you that you need OR instead of AND.
SELECT column1, column2
FROM yourtable
WHERE column1 = column2
OR column1 = 0;
After googling for an answer, I could find one site to write queries with sample data in it (sample data already uploaded there). It is very helpful to quickly find answers. So, I am gonna post it here.
https://data.stackexchange.com/stackoverflow/query/edit/1604254

Select and append rows with null value (SQL/VBA) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Can someone help in coding a Access SQL statement/Query where I have a table with columns as shown with Ident No not primary
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------null---------null--------null--------null
1----------------null--------null---------ghi----------jkl----------null--------null
1----------------null--------null---------null---------null--------mno--------pqr
Looking for result as shown below in the query result or a new table.
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------ghi---------jkl--------mno--------pqr
Please Help Thanks in advance
You need to use group by and get the MAX() value for each column like
select `Ident_No`, max(`Data1`), max(`Data2`),
max(`Data3`), max(`Data4`), max(`Data5`), max(`Data6`)
from tbl9999
group by Ident_No
See live here http://rextester.com/CIHY78216

Is something wrong with my SQL Query? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
SELECT * FROM iveflownthat.messages WHERE from=1 OR to=1
Its keeps giving me errors. I checked to make sure that the fields, table, and database name are correct.
FROM and TO are keywords. You should use them like this: [FROM], [TO]
SELECT * FROM iveflownthat.messages WHERE [from]=1 OR [to]=1
"from" is a keyword in SQL. ENclose it in square brackets... " WHERE [from] = 1 OR [to] = 1 "
edit" What Alireza said...
You named your column 'from' which is a reserved word, so you're getting this error due to bad syntax.

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 %.