Solved

error on sql dynamic with uniqueidentifier

Posted on 2011-02-13
8
420 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
Comment Utility
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
Comment Utility
Hi,

Change execute @sql5

for

execute (@sql5)
0
 
LVL 16

Expert Comment

by:BurnieP
Comment Utility
Ah, too slow :)
0
 

Author Comment

by:bibi92
Comment Utility
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
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.

 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

763 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

11 Experts available now in Live!

Get 1:1 Help Now