467,926 Members | 1,724 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Query works fine as direct query but not in stored proc

dbrewerton
100+
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;
  13.  
Feb 5 '20 #1

✓ answered by Rabbit

Try disambiguating query by supplying the database name and schema like you did with the other tables.

  • viewed: 1840
Share:
1 Reply
Rabbit
Expert Mod 8TB
Try disambiguating query by supplying the database name and schema like you did with the other tables.
Feb 5 '20 #2

Post your reply

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

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.