I have a query inside my stored procedure:
IF @backup = 0
BEGIN
SELECT sql = 'BACKUP DATABASE MyDatabase TO DISK="'+@file+'"';
END
@file is nvarchar(MAX) and backup is int.
If I execute the stored procedure like:
DECLARE @return_value int
EXEC @return_value = [dbo].[usp_cp_backup_restore_db]
@backup = 0,
@file = N'C:\backupFiles\MyDatabase.bak'
but the result becomes:
BACKUP DATABASE ContentPlatform TO DISK="C:\backupFiles\MyDatabase.bak"
I want to appear BACKUP DATABASE ContentPlatform TO DISK='C:\backupFiles\MyDatabase.bak'
because the correct format is
BACKUP
DATABASE MyDatabase TO
DISK='C:\MyDatabase.bak'
Any suggestions ?
Thanks
Instead of using
"in your initial strings, use''instead. SQL knows, if you put two'next to each other, that you mean'to appear in the string (as opposed to ending one string and starting another.)It looks odd, sure, but it works.