April 1, 2022 at 4:04 pm
Hi All,
Here is the data, I want to get result from the beginning up to including end of the \.
ex:
\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_1\FULL\
\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_2\FULL\
\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_3\FULL\
\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\DB_4\FULL\
Can you help.
create table #tbl_backup_path (backup_path varchar (8000))
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_1\FULL\ServerName$SQLEXPRESS_db_1_FULL_20220327_031546.bak')
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_2\FULL\ServerName$SQLEXPRESS_db_2_FULL_20220327_031551.bak')
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_3\FULL\ServerName$SQLEXPRESS_db_3_FULL_20220327_031552.bak')
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\DB_4\FULL\ServerName$SQLEXPRESS_DB_4_FULL_20220327_031554.bak')
select * from #tbl_backup_path
drop table #tbl_backup_path
April 1, 2022 at 4:20 pm
Which \?
Can you give an example of what you're trying to return? My mindreading skills are taking April Fool's Day off.
April 1, 2022 at 4:39 pm
I want to return the up to last \ (OR) FULL\.
ex:
\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\db_1\FULL\
April 2, 2022 at 3:01 am
Oh, okay, Gotcha. Something like this?
select backup_path
, LEFT(backup_path,CHARINDEX('\FULL\',backup_path,1) + LEN('FULL\'))
from #tbl_backup_path;
April 2, 2022 at 5:16 pm
pietlinden wrote:Oh, okay, Gotcha. Something like this?
select backup_path
, LEFT(backup_path,CHARINDEX('\FULL\',backup_path,1) + LEN('FULL\'))
from #tbl_backup_path;Thank you working perfect.
Do you understand how and why it works?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 4, 2022 at 2:26 am
Add another row to the sample table:
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\DB_4\DIFF\ServerName$SQLEXPRESS_DB_4_DIFF_20220327_032554.bak')
Does the query produce the expected result now?
_____________
Code for TallyGenerator
April 4, 2022 at 2:31 pm
I'd urge you not to write a query based only on current data, but to make it more flexible:
--
insert into #tbl_backup_path values ('\\x.x.x.x\Database_Backup_Daily\ServerName$SQLEXPRESS\DB_5\DIFF\ServerName$SQLEXPRESS_DB_4_FULL_20220327_091554.diff')
SELECT backup_path, LEFT(backup_path, LEN(backup_path) - CHARINDEX('\', REVERSE(backup_path)) + 1)
FROM #tbl_backup_path
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply