July 14, 2011 at 9:18 pm
Hi,
Can any one help me please
I have a column called Drive in a table A
Contents of the table A are as described below.
Drive
------
K:\Backups\Differential\development.bak
-------------------------------------------------------------------
@Database=Test, @FileName=K:\BackupS\Differential\Test\Test_Diff_2007-07-12-220004.bak, @FileNumber=0, @Desc=Backup differential database of Reports on 7/12/2007 10:00:04 PM, @BackupName=Backup differential database of Test, @RetainDays=1, @Init=1, @Priority=0, @With=DIFFERENTIAL, @Logging=0, @Affinity=255, @MaxTransferSize=1048576, @Throttle=50, @BufferCount=20, @CompressionLevel=4, @OLRMAP=0
----------------------------------------------------------------------
I need to write a select statement which should give me output like this
Drive
-------------
K:\Backups\Differential\development.bak
-------------
K:\BackupS\Differential\Test\Test_Diff_2007-07-12-220004.bak
Both of the rows which i had described above are two rows in a single column.
Can any one please help me with the code.
Thanks in advance,
Thank You,
July 14, 2011 at 9:37 pm
You can use SUBSTRING & CHARINDEX functions to retrieve the data.
The example is as below:
declare @aa nvarchar(100) = '@Database=Test, @FileName=K:\BackupS\Differential\Test\Test_Diff_2007-07-12-220004.bak, @FileNumber'
select SUBSTRING(@aa, Charindex('K:', @aa), charindex('.bak', @aa) - (Charindex('K:', @aa)-4))
It returns:
K:\BackupS\Differential\Test\Test_Diff_2007-07-12-220004.bak
Thanks
July 14, 2011 at 10:10 pm
SQL2k8, if the above didn't help you, can you make that into a CREATE TABLE and INSERT statement for us, so we can see exactly what you're seeing?
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
July 15, 2011 at 12:15 am
Details are in the comments in the code...
--===== Create a test table. This is NOT a part of the solution.
CREATE TABLE TableA
(
Drive VARCHAR(1000)
)
;
--===== Populate the test table. Notice the different drive letters.
-- Again, this is NOT a part of the solution.
INSERT INTO TableA
SELECT 'K:\Backups\Differential\development.bak' UNION ALL
SELECT '@Database=Test, @FileName=K:\BackupS\Differential\Test\Test_Diff_2007-07-12-220004.bak, @FileNumber=0, @Desc=Backup differential database of Reports on 7/12/2007 10:00:04 PM, @BackupName=Backup differential database of Test, @RetainDays=1, @Init=1, @Priority=0, @With=DIFFERENTIAL, @Logging=0, @Affinity=255, @MaxTransferSize=1048576, @Throttle=50, @BufferCount=20, @CompressionLevel=4, @OLRMAP=0' UNION ALL
SELECT '@Database=Test, @FileName=Z:\BackupS\Differential\Test\Test_Diff_2007-07-13-001015.bak, @FileNumber=0, @Desc=Backup differential database of Reports on 7/12/2007 10:00:04 PM, @BackupName=Backup differential database of Test, @RetainDays=1, @Init=1, @Priority=0, @With=DIFFERENTIAL, @Logging=0, @Affinity=255, @MaxTransferSize=1048576, @Throttle=50, @BufferCount=20, @CompressionLevel=4, @OLRMAP=0'
;
--===== Making the terrible assumption that all backup files will have the extension of ".bak",
-- find the full drive:\path\filename.bak no matter what the drive letter is.
SELECT SUBSTRING(Drive,PATINDEX('%[A-Z]:\%',Drive),CHARINDEX('.bak',Drive)+4-PATINDEX('%[A-Z]:\%',Drive))
FROM TableA
;
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2011 at 7:54 am
Thank You very much. Your code works
July 15, 2011 at 7:55 am
the below code also works
July 17, 2011 at 10:52 pm
sql2k8 (7/15/2011)
the below code also works
code please..
Thanks
July 18, 2011 at 4:30 am
Hardy21 (7/17/2011)
sql2k8 (7/15/2011)
the below code also workscode please..
It's a "newbie" forum mistake. His first post where the OP said "Thank You very much. Your code works " was in reference to your good code. His second post of "the below code also works " was in reference to my code because my code is physically below your code on this thread.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 19, 2011 at 2:08 am
Jeff Moden (7/18/2011)
Hardy21 (7/17/2011)
sql2k8 (7/15/2011)
the below code also workscode please..
It's a "newbie" forum mistake. His first post where the OP said "Thank You very much. Your code works " was in reference to your good code. His second post of "the below code also works " was in reference to my code because my code is physically below your code on this thread.
Great 🙂
Thanks
July 20, 2011 at 12:37 am
Hi
Just a hint, if you are doing backup monitoring instead of using output from funny programs and try to format them.
Checkout msdb
backupset
backupmedia
backupmediafamily
Even if you use 3rd party apps, these tables still hold the info for the dates backed up, location and times.
It also populates that GUI that says, "last backup date"
Cheers
Jannie
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply