473,386 Members | 1,823 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,386 software developers and data experts.

What's wrong in this query ?

Hi. I have a SP named, for instance, SP1.

I need to execute something like

SELECT Sum([Field1]) FROM SP1 WHERE [SP1].[Field1]='0'

and I get the message:

Server: Msg 208, Level 16, State 3, Line 1
Invalid object name 'SP1'.

However, SP1 *IS THERE* and runs fine !!!

Thanks
Alex

May 24 '06 #1
4 1411
On 23 May 2006 20:19:56 -0700, Radu wrote:
Hi. I have a SP named, for instance, SP1.

I need to execute something like

SELECT Sum([Field1]) FROM SP1 WHERE [SP1].[Field1]='0'

and I get the message:

Server: Msg 208, Level 16, State 3, Line 1
Invalid object name 'SP1'.

However, SP1 *IS THERE* and runs fine !!!


Hi Alex,

I hope that you are not really trying to sum a character column or
comparing a numeric column to a string constant. And I also hope that
you're not really writing a query to calculate the SUM of lots of
zeroes. <g>

You can only include tables and views in a FROM clause, not stored
procedures.

Try it like this:

CREATE TABLE #temp
(Co1umn1 .....,
....)

INSERT INTO #temp (Column1, ...)
EXECUTE SP1

SELECT whatever
FROM #temp
WHERE Column1 = 0

--
Hugo Kornelis, SQL Server MVP
May 24 '06 #2
Radu (cu*************@yahoo.com) writes:
Hi. I have a SP named, for instance, SP1.

I need to execute something like

SELECT Sum([Field1]) FROM SP1 WHERE [SP1].[Field1]='0'

and I get the message:

Server: Msg 208, Level 16, State 3, Line 1
Invalid object name 'SP1'.

However, SP1 *IS THERE* and runs fine !!!


Sure. But you in the FROM clause you can use any of the following:

o A table
o A view.
o A table-valued function.
o A derived table. (That is a free-standing SELECT statement).
o A rowset function. (OPENQUERY, OPENXML etc)

But you cannot use a stored procedure. A stored procedure can return
0 to many result sets, and each invocation can, theoretically, yield
different results with different layout. A source in a FROM clause must
have a consistent set of columns.

Look at http://www.sommarskog.se/share_data.html for some ideas.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 24 '06 #3
A stored procedure is not an object such as a table or a view..."select
from" apply only to objects...Hint: if possible use a view...

May 24 '06 #4
Thank you all for your answers. Now it's clear - I'm using a TEMP table
i.e. "Select .... into #Temp" instead of the subquery, and then "Select
.... from #Temp". Now it's okay.

Thank you again

Alex.

May 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve | last post by:
Hi, Is there something fundamentally wrong with the following query? SELECT MAX(OrderID) AS Expr1 FROM Orders WHERE (MarketActionCode = 'S') AND (OrderLegCode = 'S') AND (Status = 'F') AND...
5
by: Krisnamourt Correia via SQLMonster.com | last post by:
I have one query that executes many times in a week. I created one Maintenances plan that Rebuild all index in my Database that has been executed at 23:40 Saturday until stop finished at Sunday. ...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
3
by: Lauren Wilson | last post by:
The following query runs just fine in the Access 2003 interface. strSQL = "SELECT tblCASES.CID, tblCASES. AS , tblCONTACTS.FirstName, tblCONTACTS.MiddleInitial, " & _ "tblCONTACTS.LastName,...
1
by: iam247 | last post by:
Hi I have a web page which receives information from a form (using request.form) and also attempts to look at an Access query to read in recoeds to a variable named rsGroup. When I have the...
2
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
8
by: Shelly | last post by:
I get an error that the input string is not in the right format. Here is the result: Here is the partial code: Dim sqlConn As New SqlConnection(SqlDataSource1.ConnectionString) Dim query As...
4
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Here is what I have: private int NationalCount() { Int32 numRecords = 0; using (SqlConnection dataConnection = new SqlConnection(GlobalVars.sqlConnString)) { SqlCommand dataCommand = new...
3
by: canabatz | last post by:
im using paging on this query: i got this code that returning wrong results: (SELECT bid_price, count(*) as n from bidding_details where bid_id=$bid_id GROUP BY bid_price DESC HAVING n = 1 ) ...
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.