Solved

What is wrong with the following job?

Posted on 2011-09-22
7
1,704 Views
Last Modified: 2012-05-12
Hi, I got this error when I run the bellow job:

"Executed as user: NT AUTHORITY\SYSTEM. Unclosed quotation mark after the character string 'D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup2292011'. [SQLSTATE 42000] (Error 105)  Incorrect syntax near 'D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup2292011'. [SQLSTATE 42000] (Error 102).  The step failed."


Here is th job

DECLARE @backupDate nvarchar(8)
declare @deletedate datetime
declare @statement nvarchar(100)
set @backupDate =cast(day(getdate())as nvarchar)
				+cast (month(getdate())as nvarchar)
				+cast (year(getdate())as nvarchar)
				
 select @deletedate= DATEADD(dd,-3,GETDATE())				
execute xp_delete_file 0, 'D:\Development\Menafn_Sql_Backup_daily', 'bak', @deletedate

set @statement ='BACKUP DATABASE menafn 
		TO DISK = ''D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup'
		+@backupdate+
		'.bak'''
 
execute (@statement)

Open in new window

0
Comment
Question by:Sindibad_123
  • 3
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 36579866
I think you want

set @statement ='Backup DATABASE menafn TO DISK = ''D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup' +@backupdate+ '.bak'''
0
 

Author Comment

by:Sindibad_123
ID: 36579926
Still the same error:

Executed as user: NT AUTHORITY\SYSTEM. Unclosed quotation mark after the character string 'D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup2292011.bak'. [SQLSTATE 42000] (Error 105)  Incorrect syntax near 'D:\Development\Menafn_Sql_Backup_daily\menafnfullbackup2292011.bak'. [SQLSTATE 42000] (Error 102).  The step failed.
0
 
LVL 13

Accepted Solution

by:
Philip Pinnell earned 500 total points
ID: 36579963
Ha!

try
declare @statement nvarchar(200)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 21

Expert Comment

by:JestersGrind
ID: 36579996
You can comment out the execute and substitute in PRINT @Statement to see what exactly is being executed.  The issue usually becomes obvious at that point.  You will also be able to run the output to verify that it works.

Greg

0
 

Author Comment

by:Sindibad_123
ID: 36579999
Good catch
0
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36580010
Andy nailed it.  You variable length is too short so it's truncating the string.  

Greg

0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 36580064
Easily done.

Thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now