Select a part of a selected item in 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 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

Related

In Sql developer ,How to remove the last 3 digit from string in all rows for one 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 9 months ago.
Improve this question
Colum2
Karim_bk
Karim_bk
Karim_bk
Want result Karim
This should work
select top 10 Lastname, LEFT(Lastname, LEN(Lastname) - 3) as TrimmedVersion from tablename
Hope this will help you. In Oracle:
SELECT SUBSTR(column_name, 0, LENGTH(column_name) - 2) from table_name;
--SELECT SUBSTR('karim_bk', 0, LENGTH('karim_bk') - 2) from dual; --karim

Oracle SQL Select Only 5 Digit Row in a Column [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 2 years ago.
Improve this question
SELECT *
FROM GNGRB.CLAIM
WHERE ZOCRECDT IS NOT NULL;
SLNO Column select only 5 digit row
Please use length function of oracle. For e.g:
select *
from table a
where length(a.column_name) = 5
In your case
SELECT *
FROM GNGRB.CLAIM
WHERE ZOCRECDT IS NOT NULL
and LENGTH(SLNO) = 5

How to get number without null before dot? [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
.00012 $
from 0.00012
but
1.0002 $ from 1.0002
Is this possible in postgress?
You can use something like below -
With t as
(Select 1.0002 As Value
UNION ALL
Select .00012 As Value
)
Select to_char(Value,concat('FM$999,999,999,990D',repeat('0',length(cast(Value as varchar))-2))) from t;
Below is a DB fiddle link to illustrate - https://dbfiddle.uk/?rdbms=postgres_9.5&fiddle=a8e9a3207305b011f5bf7be58ce04180
EDIT : As I thought more about the problem, I realized that the solution above would work for the examples that you have shared but it is not a generalized solution. Below would be a more general approach to solve the problem :
With t as
(Select 1.0002 As Value
UNION ALL
Select .00012 As Value
UNION ALL
Select 100.003 As Value
UNION ALL
Select 12.34456 As Value
UNION ALL
Select 5000.30 As Value
)
Select to_char(Value,concat('FM$999,999,999,990D',repeat('0',length(cast(Value as varchar))-length(cast(ROUND(Value,0) as varchar))-1))) As Amt from t;
DB fiddle link - https://dbfiddle.uk/?rdbms=postgres_9.5&fiddle=ff6f59fdd499941ee1cb1e0fc57e08ca

case when with count [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 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;

How to Use BETWEEN and LIKE in T-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 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]';