?
Solved

sql query to reportserver  table error

Posted on 2016-11-25
3
Medium Priority
?
72 Views
Last Modified: 2016-11-25
I have a query below which run fine except when I include the join to the sysjobs table, I just can't figure out why the query get error, anyone has ideas where and how to start troubleshooting ? Here is the error message return.

Msg 8169, Level 16, State 2, Line 17
Conversion failed when converting from a character string to uniqueidentifier.



SELECT
          c.Name AS ReportName
          , rs.ScheduleID AS JOB_NAME
          , s.[Description]
          , s.LastStatus
          , s.LastRunTime
          --,JBS.Name
              --INTO drop table JOBS_Error
    FROM
          ReportServer..[Catalog] c
          JOIN ReportServer..Subscriptions s ON c.ItemID = s.Report_OID
          JOIN ReportServer..ReportSchedule rs ON c.ItemID = rs.ReportID
          JOIN msdb..sysjobs jbs ON JBS.Name = rs.ScheduleID
          AND rs.SubscriptionID = s.SubscriptionID
0
Comment
Question by:motioneye
[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 Comments
 
LVL 29

Accepted Solution

by:
Pawan Kumar earned 1000 total points
ID: 41901328
Try..

rs.ScheduleID is of type UniqueIdentifier and JBS.Name is of type Varchar.

SELECT
          c.Name AS ReportName
          , rs.ScheduleID AS JOB_NAME
          , s.[Description]
          , s.LastStatus
          , s.LastRunTime
          ,JBS.Name 
              --INTO drop table JOBS_Error
    FROM
          ReportServer..[Catalog] c
          JOIN ReportServer..Subscriptions s ON c.ItemID = s.Report_OID
          JOIN ReportServer..ReportSchedule rs ON c.ItemID = rs.ReportID
          JOIN msdb..sysjobs jbs ON JBS.Name = CAST(rs.ScheduleID AS VARCHAR(100))
          AND rs.SubscriptionID = s.SubscriptionID

Open in new window

0
 
LVL 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1000 total points
ID: 41901337
As the error states you can't join columns with different types. Name is varchar and ScheduleID is uniqueidentifier.
As stated the MSDN article the uniqueidentifier type is limited to 36 characters so you just need to convert it to a VARCHAR(36) data type to have your query working properly:
    JOIN msdb..sysjobs jbs ON JBS.Name = CAST(rs.ScheduleID AS VARCHAR(36))
0
 

Author Closing Comment

by:motioneye
ID: 41902100
Thanks both of you .
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

801 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