Database Administrators
Q&A for database professionals who wish to improve their database skills
Latest Questions
0
votes
2
answers
1100
views
How to rtrim the slash character (/)?
rtrim('txt/','/') What if we cannot use this version of the rtrim function.. How else to remove the trailing '/' from the end of a string (if present)?
rtrim('txt/','/')
What if we cannot use this version of the rtrim function.. How else to remove the trailing '/' from the end of a string (if present)?
simpatico
(99 rep)
Nov 3, 2022, 12:55 PM
• Last activity: Nov 3, 2022, 09:17 PM
0
votes
2
answers
1395
views
updating values in table to remove specific word
[![enter image description here][1]][1] [1]: https://i.sstatic.net/TFehq.png Some of my data has **- Automated** two or more times. I need to replace the text so it only appears once I first tried to get the value to display by using this failed query SELECT TRIM('- Automated') As TrimmedString FROM...

GettingStarted
(176 rep)
Nov 23, 2021, 05:02 PM
• Last activity: Nov 23, 2021, 09:20 PM
0
votes
2
answers
196
views
MS SQL: SSD Trim after TRUNCATE / DROP?
I consider to use one of those fancy new SSD-only SAN systems for our new Microsoft SQL Server. "Fancy" means, that it supports / use stuff as block compression / deduplication / 0x00-recognitation / disk space overprovioning etc. When I drop or truncate a table the SQL server usually only marks the...
I consider to use one of those fancy new SSD-only SAN systems for our new Microsoft SQL Server. "Fancy" means, that it supports / use stuff as block compression / deduplication / 0x00-recognitation / disk space overprovioning etc.
When I drop or truncate a table the SQL server usually only marks the pages in the page allocation map as free, but does not touch the data in the pages itself (e.g. overwriting it with 0x00). This is very fine (because fast) with HDDs but SSDs prever to know if a block is free and could be overwritten by its internal routines or if the data are still important and needs to be preserved.
So my question: does the Microsoft SQL Server supports the SSD-Trim-Command to deallocate space in some way? Of course without shrinking shrinking the file or doing other manual / slow stuff which fragments my indexes, blocks my queries etc.
Or is there a way to force the SQL server to overwrite the unassigned data by 0x00 (which will be recognized by the SAN, so it frees up the space internal), even if this is the worser option compared to the SSD-TRIM?
PS: I know that it usually makes sense to have some (!) unassigned space in the database files to use for new data, but just assume that I delete more than I will add in the next 6 months or that I work with partitions and the deleted stuff resists in other files than the current hot data (but the old filegroup is still not empty, so it can't be dropped / shrinked).
Thomas Franz
(885 rep)
Oct 25, 2021, 11:59 AM
• Last activity: Oct 29, 2021, 02:54 PM
1
votes
1
answers
802
views
To trim particular value in a column in Oracle sql
I have a regular expression select statement like below : SELECT REGEXP_REPLACE(nvl(l.text_1, l.text),'^'||21810||'=|\|' ||21810||'=', '|'||21810||'='||'B1') FROM table_1 1 This checks the value of texts and add's B1 if the text has 21810 eg: If my text is `21614=C1||21810=C2` what it does is : `216...
I have a regular expression select statement like below :
SELECT REGEXP_REPLACE(nvl(l.text_1, l.text),'^'||21810||'=|\|'
||21810||'=', '|'||21810||'='||'B1')
FROM table_1 1
This checks the value of texts and add's B1 if the text has 21810
eg: If my text is
21614=C1||21810=C2
what it does is : 21614=C1|||||||21810=B1C2
But I want this to remove this C1 and C2 which is always followed by a '=' and just add B1 after '=' in 21810
21614=|||||||21810=B1
Sangathamilan Ravichadnran
(135 rep)
Jul 23, 2021, 12:28 PM
• Last activity: Jul 24, 2021, 11:55 PM
0
votes
1
answers
40
views
How to concatenate these two statements (RIGHT and LEFT)? I am trying to trim two characters off both the beginning and end of cell
Is it possible to either combine or concatenate the following two statements? RIGHT(wp_postmeta.meta_value, LENGTH(meta_value) -2) LEFT(wp_postmeta.meta_value, LENGTH(meta_value) -2) What I am ultimately trying to do is strip the first two and last two characters from a field (for display or output...
Is it possible to either combine or concatenate the following two statements?
RIGHT(wp_postmeta.meta_value, LENGTH(meta_value) -2)
LEFT(wp_postmeta.meta_value, LENGTH(meta_value) -2)
What I am ultimately trying to do is strip the first two and last two characters from a field (for display or output only...I am not trying to modify or replace anything in my database).
Below is my full query, which works great...except the output of wp_postmeta.meta_value is a URL encased with [" and "].
SELECT wp_download_log.ID, wp_download_log.download_date, wp_posts.post_title,
(SELECT group_concat(wp_terms.name separator ', ') FROM wp_terms
INNER JOIN wp_term_taxonomy on wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships wpr on wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
WHERE taxonomy= 'dlm_download_category' and wp_posts.ID = wpr.object_id ) AS "Categories",
wp_postmeta.meta_value, wp_download_log.download_id, wp_download_log.version_id, wp_download_log.user_id, wp_download_log.user_ip, wp_download_log.user_agent
FROM wp_posts
LEFT JOIN wp_download_log ON wp_posts.ID = wp_download_log.download_id
LEFT JOIN wp_postmeta ON wp_download_log.version_id = wp_postmeta.post_id
WHERE wp_postmeta.meta_key = '_files'
In there you will see that one column I am trying to output is wp_postmeta.meta_value where wp_postmeta.meta_key = '_files'.
Inserting one of my two statements I am trying to combine in place of wp_postmeta.meta_value works great. Inserting both works too...I just have two columns.
With my search for a unified solution coming up dry, I have been trying for the past hour or two to concatenate the two to get the contents of wp_postmeta.meta_value WHERE meta_key = '_files' into a single field, sans the first two and last two characters, but I have yet to figure out how.
Surely there is a SQL solution here without having to manually process the column in Excel with each export?
user2461674
(23 rep)
Mar 5, 2020, 03:10 AM
• Last activity: Mar 5, 2020, 03:56 AM
1
votes
2
answers
518
views
SQL queries to get the duplicate records based on trim
I have a table that has got the below set of records. UNMASK MASK 123 897609 00123 896509 0000456 5632789 456 32567889 5678 5632789 From the above table I need to select only the below records. UNMASK 123 00123 0000456 456 (I.E) Whatever values in UNMASK has any number of '0' before the '1-9' and al...
I have a table that has got the below set of records.
UNMASK MASK
123 897609
00123 896509
0000456 5632789
456 32567889
5678 5632789
From the above table I need to select only the below records.
UNMASK
123
00123
0000456
456
(I.E) Whatever values in UNMASK has any number of '0' before the '1-9' and also the row that doesn't have 0s before that 1-9.
Like 123 and there can be 000000123, 456 and 00456, I need such records(only Prefixed with 0s and the original value) in the output using SQL query in Oracle.
I tried the below query but it doesn't work the way I want.
Select UNMASK,TRIM (LEADING '0' FROM UNMASK) from HSA.TEST_TABLE group by UNMASK having count(TRIM(LEADING '0' FROM UNMASK)) > 1;
sabarish jackson
(133 rep)
May 16, 2019, 03:32 PM
• Last activity: May 17, 2019, 11:01 AM
1
votes
1
answers
1686
views
Using SUBSTRING and RTRIM Together
I have a VARCHAR field that contains a city and a 2 digit state abbreviation, but there tends to be leading and trailing spaces in the field. I need to parse out the City and State Abbrev into separate fields. Currently I just have this to parse out the State, but I have no idea how to handle the Ci...
I have a VARCHAR field that contains a city and a 2 digit state abbreviation, but there tends to be leading and trailing spaces in the field. I need to parse out the City and State Abbrev into separate fields. Currently I just have this to parse out the State, but I have no idea how to handle the City
RIGHT(RTRIM(alt.Address),2)
Daylon Hunt
(189 rep)
May 8, 2019, 09:34 PM
• Last activity: May 8, 2019, 10:21 PM
3
votes
1
answers
118
views
Unexpected behavior from ltrim in postgres
select ltrim('Test Thing', 'Test '); Expected: 'Thing' Actual Result: 'hing' Why does the 'T' in 'Test' match and trim the 'T' from 'Thing'?
select ltrim('Test Thing', 'Test ');
Expected: 'Thing'
Actual Result: 'hing'
Why does the 'T' in 'Test' match and trim the 'T' from 'Thing'?
jarbot
(31 rep)
Apr 26, 2019, 09:23 PM
• Last activity: Apr 28, 2019, 12:15 PM
2
votes
2
answers
35023
views
How To Remove Spaces Between Characters In PostgreSQL?
I want to match two tables based on a specific column which is a card number, there are spaces between characters in some of card numbers in the second table like below: 'NES 123_4_5' 'MTS 678_9_0' What i want is to remove the space between the characters and numbers and change it to following form:...
I want to match two tables based on a specific column which is a card number, there are spaces between characters in some of card numbers in the second table like below:
'NES 123_4_5'
'MTS 678_9_0'
What i want is to remove the space between the characters and numbers and change it to following form:
'NES123_4_5'
'MTS678_9_0'
What would be the SQL query of function to do this?
Sayad Xiarkakh
(532 rep)
Oct 30, 2016, 08:59 AM
• Last activity: Oct 30, 2016, 09:27 AM
0
votes
4
answers
1424
views
TRIM() Function With Linked Server
I have a linked server connection for a `postgresql` into `sql server`. I can run this in Sql Server `Select * from OpenQuery(LinkedServer,'Select * from alphadawg')` and this returns all results, but the second I try to add in any functions I start getting errors. For example, if I wanted to `TRIM(...
I have a linked server connection for a
Incorrect syntax near ' from ad.userid) As "User ID" Okay, so maybe the issue is I am trying to execute postgresql in Sql Server, so I altered the syntax to Select * from OPENQUERY(LinkedServer, 'Select RTRIM(ad.userid) As "User ID" FROM alphadawg ad') But that then threw an error of: > OLE DB provider "MSDASQL" for linked server "LinkedServer" returned message "Requested conversion is not supported.". How can you use the
postgresql
into sql server
. I can run this in Sql Server Select * from OpenQuery(LinkedServer,'Select * from alphadawg')
and this returns all results, but the second I try to add in any functions I start getting errors. For example, if I wanted to TRIM()
the trailing spaces off of a field
Select * from OPENQUERY(LinkedServer,
'Select TRIM(trailing ' ' from ad.userid) As "User ID"
FROM alphadawg ad')
I get an error of
> Msg 102, Level 15, State 1, Line 5Incorrect syntax near ' from ad.userid) As "User ID" Okay, so maybe the issue is I am trying to execute postgresql in Sql Server, so I altered the syntax to Select * from OPENQUERY(LinkedServer, 'Select RTRIM(ad.userid) As "User ID" FROM alphadawg ad') But that then threw an error of: > OLE DB provider "MSDASQL" for linked server "LinkedServer" returned message "Requested conversion is not supported.". How can you use the
TRIM()
function with a linked server connection between postgresql and SQL Server?
user2676140
(960 rep)
Aug 24, 2016, 12:47 PM
• Last activity: Aug 24, 2016, 02:19 PM
2
votes
1
answers
2950
views
Trim a value in an xml column in MS SQL Server
I have a database with an XML column. I am trying to update (trim) an xml value of the xml column. I am running on Windows, SQL Server 2008 Express. I did not find any way to trim directly in Xquery so I tried by selecting the value. Here is the SQL select RTRIM(LTRIM(col2.value('(/Root/Row/Rowid/te...
I have a database with an XML column. I am trying to update (trim) an xml value of the xml column. I am running on Windows, SQL Server 2008 Express.
I did not find any way to trim directly in Xquery so I tried by selecting the value. Here is the SQL
select RTRIM(LTRIM(col2.value('(/Root/Row/Rowid/text())','varchar(20)')))
from dbo.T1
But now I am not getting how to update this xml value.
Is there any way to Trim the xml value directly? If not how can I Trim the value?
I am not trying to update the single row in the table, I am trying to trim the xml value of all the rows in the table
IT researcher
(3178 rep)
Jun 22, 2016, 09:44 AM
• Last activity: Jun 24, 2016, 07:23 PM
Showing page 1 of 11 total questions