Solved

error on sql dynamic with uniqueidentifier

Posted on 2011-02-13
8
421 Views
Last Modified: 2012-05-11
Hello,

declare @sql5 varchar(max)

set @sql5 = 'DECLARE @job_id uniqueidentifier

SELECT
            @job_id = job_id

FROM
            '+ @abonne + '.msdb.dbo.sysjobs_view
WHERE
            name like N''' + @publication + '''
print @job_id
IF @job_id IS NOT NULL BEGIN
      EXEC ('+ @abonne +'.msdb.dbo.sp_delete_job @job_id = @job_id)
END

'
print @sql5
execute @sql5



The name 'DECLARE @job_id uniqueidentifier

SELECT
            @job_id = job_id

FROM
            [serverdest].msdb.dbo.sysjobs_view
WHERE
            name like N'%jobname%'
print @job_id
IF @job_id IS NOT NULL BEGIN
      EXEC ([serverdest].msdb.dbo.sp_delete_job @job_id = @job_id)
END

' is not a valid identifier.

How can I resolve this problem?

Thanks

Bibi
0
Comment
Question by:bibi92
  • 3
  • 3
  • 2
8 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34883973
Please try the following:

declare @sql5 varchar(max)

set @sql5 = 'DECLARE @job_id uniqueidentifier

SELECT
            @job_id = job_id

FROM
            '+ @abonne + '.msdb.dbo.sysjobs_view
WHERE
            name like N''' + @publication + '''
print @job_id
IF @job_id IS NOT NULL BEGIN
      EXEC ('''+ @abonne +'.msdb.dbo.sp_delete_job @job_id = '' + @job_id )
END

'
print @sql5
execute (@sql5)

Open in new window

0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34883981
Hi,

Change execute @sql5

for

execute (@sql5)
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34883984
Ah, too slow :)
0
 

Author Comment

by:bibi92
ID: 34884344
Thanks but I have this error :
Msg 168, Level 15, State 1, Line 1
The floating point value '2886E768' is out of the range of computer representation (8 bytes).
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
Regards
bibi
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 34884567
Please try the following:

set @sql5 = 'DECLARE @job_id uniqueidentifier

SELECT
            @job_id = job_id

FROM
            '+ @abonne + '.msdb.dbo.sysjobs_view
WHERE
            name like N''' + @publication + '''
print @job_id
IF @job_id IS NOT NULL BEGIN
      EXEC ('''+ @abonne +'.msdb.dbo.sp_delete_job @job_id = '''''' + @job_id + '''''''' )
END

'
print @sql5
execute (@sql5)

Open in new window

0
 

Author Comment

by:bibi92
ID: 34884587
Doesn't work, the print @sql5 :
print @job_id
IF @job_id IS NOT NULL BEGIN
      EXEC ('server].msdb.dbo.sp_delete_job @job_id = ''' + @job_id + '''' )
END
Thanks

Regards
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34887980
I think the solution was reached based on information from the posts. Specially the "execute (@sql5)" tip. So, I believe points should be given.
0
 

Author Closing Comment

by:bibi92
ID: 34889791
Sorry Thanks bibi
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

932 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

7 Experts available now in Live!

Get 1:1 Help Now