You are here: Re: What's wrong in this query ? « MsSQL Server « IT news, forums, messages
Re: What's wrong in this query ?

Posted by Erland Sommarskog on 10/02/16 11:48

Radu (cuca_macaii2000@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, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация