LastIndexOf in TSQL

I came a cross a case where I need to parse a string and get a everything after specific character. Unfortunately there is no a function that is being shipped out of the box with MS SQL Server that is doing the needed job. So we had to use 3 built-in functions in SQL in order to do the job, here is a sample TSQL statement that demonstrate how you can do it

DECLARE @SomeString VARCHAR(100)
SET @SomeString = 'Part1;Part2;Part3'

SELECT RIGHT(@SomeString, CHARINDEX(';', REVERSE(@SomeString) + ';') - 1)

Restore SQL Database from Backup on Network

Couple of weeks ago, I overcome situation where I need to restore SQL server database from network drive to my SQL server. An easy option was to copy the database to local drive on the SQL Server and do the normal restore operation; but that was costly in term of time and space as it was a huge database size.. by default MS SQL server doesn’t allow you to restore the database from network drive unless you enabled a couple of features in SQL Server; to do that you need to run the below SQL statement:

EXEC sp_configure 'XP_CMDSHELL' , 1
EXEC xp_Cmdshell 'net use p: \\ServerName\SharedFolderName'
EXEC xp_fixeddrives 1

to make sure the above statements configured the network drive correctly, you should see the drive name and estimated size for it as a result of executing the last SP (xp_fixeddrives). if you didn’t see the list of drives available on the server, then there something went wrong and those steps didn’t completed successfully

Completing these steps will let a drive called P: showing on your normal restore window and you can explore and locate your backup file (.Bak). also I’ve overcome a situation where the drive isn’t showing on my restore window and I can’t explore neither to locate the .bak file; even after running the above statement, so I had to delete the P drive and re-define it again.. I deleted it using the below statement then rerun the above statement and things worked fine with me

EXEC XP_CMDSHELL 'net use P: /delete'