How to Use BETWEEN and LIKE in T-SQL [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a question about T-SQL. I try constraint for my table. By the way, i want to use BETWEEN and LIKE command. I try this but it doesnt work.
SELECT * FROM
dbo.GrnStock
WHERE
StockNo BETWEEN LIKE '%823%' AND LIKE '%829%'
StockNo is NVARCHAR and has values like:
T000578
X000825
How can i solve this?

If StockNo is a varchar or nvarchar, then you could get the number part out of it.
Then you'll be able to use BETWEEN to compare that number within a range.
For strings like 'T000578' the 6 digit number is at the end.
Then you could do it like this:
SELECT *
FROM dbo.GrnStock
WHERE TRY_CAST(RIGHT(StockNo, 6) AS INT) BETWEEN 823 AND 829;
But for that range it could probably be simplified with using just a LIKE
SELECT *
FROM dbo.GrnStock
WHERE StockNo LIKE '%00082[3-9]';

Related

SQL - SELECT * FROM database.table ORDER BY uit asc [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
enter image description hereI would like to SELECT from a table where column uit consist value from 20 to 100 included. please find the attached pic as an example. After select by uit column, it will show the highlighted portion only (included "index", "index_","sales","return" and other 300+ columns)
for example: SELECT * FROM database.table ORDER BY or where...
Thank you very much!
enter image description here
SELECT
*
FROM
database.table
WHERE
"uit " BETWEEN 20
AND 100
The BETWEEN operator is inclusive: begin and end values are included - w3schools.com

query range on column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need help on query where I can do the range query based on Name Column from names.
e.g., as shown in sample data
starting from 'A% to 'C%'
and
from 'a% to 'c%'
and then from 'D%' to 'F%'
and from 'd%' and 'f%'
I need to split Name Column in 2 separate category which is from A to C and from D to F including all names with upper & lower case.
I tried with >=, <= and between, but it didn't help.
You can use regex to achieve that. Try below query
select Name,(case when name like '[A-Na-n]%' then 'Category A-N' when name like '[O-Zo-z]%' then 'Category O-Z' end)Category from names where name like '[A-Za-z]%'
Output:

Counting word frequency [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to sum the frequency of the words cumulatively in PostgreSQL
Here's my table (example)
I need sum accumulative frequency for same words, for example the expected results is:
resize (100 + 85) = 185
trabajar (75 + 73) = 148
partir (64) = 64
How can I make the query?
you need to use GROUP BY :
SELECT
word
, SUM(frecuency)
FROM tablename
GROUP BY word

SQL Server 2000: how to replace a entry with only the last 2 characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a table in a SQL Server 2000 database with a column with several entries like 01-03, 04-05. The first 2 digits are the room number and the last two digits are the bed number.
I want to replace the 01-05, 03-07 etc. with only the bed number. So only the last two charcters have to be in the column.
How do I accomplish this?
Sample data is:
In the column [Bed] with values:
22-01
08-01
09-03
01-16
Result has to be:
01
01
03
16
RIGHT should solve your problem:
SELECT RIGHT(RTRIM(Bed), 2) FROM tbl

Select a part of a selected item in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can I possibly select a part of a row data in MS Sql?
ex. Charmina (Female)
All I want to select is the Female not the whole Charmina (Female)
Try this
select substring('Charmina (Female)',
charindex('(','Charmina (Female)')+1,
LEN('Charmina (Female)')-charindex('(','Charmina (Female)')-1)
or
select stuff('Charmina (Female)',1,charindex('(','Charmina (Female)')-1,'')
You may Use SUBSTRING to get sub sequences of strings
SELECT SUBSTRING( your_Raw ,start , length ) AS Alias
FROM Your_Table