[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

error on sql dynamic with uniqueidentifier

Posted on 2011-02-13
8
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

656 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