<div>Hi all</div> <div></div> <div>I have the following select query which I am executing from SSMS 2008:</div> <div></div> <div>
SELECT tblNewsWall.ID, tblNewsWall.postOwner, tblNewsWall.postDate, tblNewsWall.postContent, aspnet_Profile2.ProfilePictureURL, aspnet_Profile2.FullName FROM tblNewsWall, aspnet_Profile2 WHERE tblNewsWall.postOwner IN (SELECT [friend1] from tblFriends WHERE friend2='name' union SELECT [friend2] from tblFriends WHERE friend1='name') AND aspnet_Profile2.ProfileUserName = tblNewsWall.postOwner
</div> <div>When I execute the query, sometimes it works but a lot of the time I get the following error: <div></div> <div>
Msg 208, Level 16, State 1, Line 1
Invalid object name 'tblNewsWall'.
</div> </div> <div> <div></div> This has really got me stumped - It it a problem with the server configuration, or the the Select statement - And why does it only error on certain
occasions?</div>
Try to see whether your query in another syntax will make a difference.
SELECT tblNewsWall.ID,tblNewsWall.postOwner
,tblNewsWall.postDate,tblNewsWall.postContent
,aspnet_Profile2.ProfilePictureURL
,aspnet_Profile2.FullName
FROM tblNewsWall INNER JOIN
aspnet_Profile2 ON aspnet_Profile2.ProfileUserName = tblNewsWall.postOwner
WHERE tblNewsWall.postOwner
IN (
SELECT [friend1] FROM tblFriends WHERE friend2 = 'name'
UNION
SELECT [friend2] FROM tblFriends WHERE friend1 = 'name')
Jim_Nuttall
Member
15 Points
12 Posts
Invalid object name Error
Apr 19, 2011 07:44 PM|LINK
Msg 208, Level 16, State 1, Line 1
Invalid object name 'tblNewsWall'.
</div> </div> <div> <div></div> This has really got me stumped - It it a problem with the server configuration, or the the Select statement - And why does it only error on certain occasions?</div>Any help really appreciated!
Many Thanks
Jim
smirnov
All-Star
23700 Points
4056 Posts
Re: Invalid object name Error
Apr 19, 2011 08:00 PM|LINK
Are you sure that you always execute it against the same database?
e.g. if you add
USE mydb
SELECT....
will you get the same error occasionally too?
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Invalid object name Error
Apr 19, 2011 08:14 PM|LINK
Try to see whether your query in another syntax will make a difference.
SELECT tblNewsWall.ID,tblNewsWall.postOwner ,tblNewsWall.postDate,tblNewsWall.postContent ,aspnet_Profile2.ProfilePictureURL ,aspnet_Profile2.FullName FROM tblNewsWall INNER JOIN aspnet_Profile2 ON aspnet_Profile2.ProfileUserName = tblNewsWall.postOwner WHERE tblNewsWall.postOwner IN ( SELECT [friend1] FROM tblFriends WHERE friend2 = 'name' UNION SELECT [friend2] FROM tblFriends WHERE friend1 = 'name')Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Jim_Nuttall
Member
15 Points
12 Posts
Re: Invalid object name Error
Apr 20, 2011 12:56 PM|LINK
Thanks guys. That's got it!