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:
Related
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 1 year ago.
Improve this question
Team Table
Player (column)
A
B
C
Expected Output: with Two columns
Player vsPlayer
A B
B C
C A
How to write a sql query to get the exact output as Expected output mentioned above.
Thanks in advance
The normal way to get combination (pairs) is to take all permutations, but where column 1 is less than column 2.
SELECT
l.player,
r.player
FROM
player l
INNER JOIN
player r
ON l.player < r.player
Demo : https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=9ce7af3d0afe89c6434cc2800dfbd2ef
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 have a quick sql data as below,
Customerid,Type
1,Adult
1,Adult
2,Adult
3,Adult
4,Teenager
4,Adult
I want the query that lists those customer no.s that do not have any other Type associated with them. For eg. 1 as only Adult associated with, same with 2. But 3 and 4 have multiple Types associated with them.
I am trying to get an output as below.
Customerid,Type
1,Adult
2,Adult
3,null
How should we tackle this.
You seem to want:
select customerid
, (case when min(type) = max(type) then min(type) end) as type
from table t
group by customerid;
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 to concatenate 10 different fields in the same table. After the field concatenated, I need to eliminate the space between all characters. 30,000
records.
CUSTOMER # FIELD 1 FIELD 3 FIELD 4 FIELD 5 FIELD 6 FIELD XX
,TO BE OR NOT, /THAT IS/ /THE Q/ OR NOT THE_ QUESTION
So, it would like like:
,TOBEORNOT,/THAT IS//THEQ/ORNOTTHE_QUESTION
With concat and replace:
select
replace(concat(field1, field2,....), ' ', '')
from customer
To count the characters use len:
select
len(replace(concat(field1, field2,....), ' ', '')) counter
from customer
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]';
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