473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Query works fine as direct query but not in stored proc

dbrewerton
115 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.

1 3356
Rabbit
12,516 Expert Mod 8TB
Try disambiguating query by supplying the database name and schema like you did with the other tables.
Feb 5 '20 #2

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

Similar topics

0
by: Raptor | last post by:
The error is the common "access denied to user@localhost on database," or whatever the exact language is. (I email from Linux so can't copy the exact wordage right now.) But like I say, it only...
0
by: Rick | last post by:
I wrote a medium length stored proc that uses both temp tables and one cursor. I compiled and it ran fine. However, we reboot our machine every weekend, and on Mondays the stored proc gets the...
1
by: droope | last post by:
I am trying to create a proc with a parm @whereclause that will have a value passed in of one to many policy ids. The parm coming into the proc looks like this, ('000000000108', '000000000106',...
9
by: kangaroo | last post by:
Hi guys, when we run a stored proc and it results into an unhandled error, the error message returned by db2 udb does not contain a line number that caused an error. This makes it pretty...
4
by: Learner | last post by:
Hi there, I have a storec proc that schedules a Sql job and finally it returns 0 then it was successfull and if it returns 1 then its unsuccessful. Now when i run the stored proc in the query...
4
by: daz_oldham | last post by:
Hi All I am trying to execute a stored procedure that does a very simple lookup and returns a text field. However, when I try to execute it, I am getting a rather strange error that I can't seem...
1
by: Psychobudgie | last post by:
Hi, I have written a stored procedure which includes a DATEPART command, i.e. DATEPART(weekday, <date>) The result when ran from SQL Query Analyser is as expected . i.e. Sunday returns 1,...
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
4
by: davinski | last post by:
Hello, it's been a while since my last post, hope everyone is fine :P I'm stuck with what seems to be a simple task, but I'm getting confused on how to complete this. Basically, I have been given...
11
George Tekos
by: George Tekos | last post by:
Good evening. i have a table that stores dates, names (of the students) and courses (that the particular student missed, because of apscence) i created a query, so i can recall a specific dates'...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.