472,805 Members | 996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 2857
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'...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.