By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Query works fine as direct query but not in stored proc

P: 114
Greetings experts. I'm trying to figure something out and I'm having no luck. This query works fine as a direct query but my requirement is to make it into a procedure. The error from the proc is "Invalid object name 'Query'". Here is the query.

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 5 Name, Sev, COUNT(SimID) AS Count
  2. FROM (
  3.     SELECT C.Name, B.SimID, (CASE 
  4.     WHEN C.Sev = 1 THEN 'Low' 
  5.     WHEN C.Sev = 2 THEN 'Medium' 
  6.     WHEN C.Sev = 3 THEN 'High' END) AS Severity
  7.     FROM [LINKEDSRV].[MYDB2].[Entities].[Scan] AS A 
  8.     INNER JOIN [LINKEDSRV].[MYDB2].[Entities].[Result] AS B ON A.Id = B.ScanId 
  9.     INNER JOIN Query AS C ON B.QueryVersionId = C.QueryId
  10.     WHERE (C.Sev = 1)) AS Z
  11. GROUP BY Name, Severity
  12. ORDER BY Severity, Count DESC;
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,392
Try disambiguating query by supplying the database name and schema like you did with the other tables.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.