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
Fieldname: DCCD
Characters in field: BAS XXXX 290 B2D explanation
I need the XXXX and want to place them in a seperate column.
The first group (ex. BAS) are always 3 characters
The The XXXX can have 2, 3 or 4 characters
The third group have 2 or 3 karakters
Between the groups there's always a space (spatie)
I got this code but it doesn't work. Can someone please help me. I don't know anything about this and I speak dutch :-)
LEFT(RIGHT([DCCD], (LEN([DCCD]) - SEARCH(" ", [DCCD]))), SEARCH(" ", RIGHT([DCCD], (LEN([DCCD]) - SEARCH(" ", [DCCD])))))
Use CHARINDEX() to find the ' ' in a string, start looking at position 5. Use SUBSTRING() to return from position 5.
substring(DCCD, 5, CHARINDEX(' ', DCCD, 5) -5)
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 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
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 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
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
Trying to get rid of a space.
Current Results:
P O BOX 140
Desired Results:
PO BOX 140
--This script did not work
update table
set column= replace(column, 'P O', 'PO')
from table
Something simple if the space is always the 2nd position....
take the left most character add the right most characters -1 for first letter and -1 for the space.
Select left('P O BOX 140',1) + right('P O BOX 140',len('P O BOX 140')-2) as NoO
...
WHERE UPPER(FieldText) Like 'P O%'
http://sqlfiddle.com/#!6/2a2dd/4/0
you could add some where clause limits to ensure the first character is P and the 3rd is O as well..