Howto call views inside another SELECT statement (SQL Server)?
-
20-09-2019 - |
Question
I created a view. The view's Query works fine. Now I want to write another Query which uses the first one. As far as I know it should look like this:
SELECT * FROM myView;
Now there is an Error returned: "Ungültiger Objektname 'myView'" in English its something like "unvalid object name 'myView'.
How do I refer to or call views the right way? I#M using SQL Server.
Solution
Check that you created the view in the right database, right schema and granted the SELECT
privilege on the view to the user that uses it.
Or, better, post the SQL
you used to create the view.
OTHER TIPS
That error usually means that you are looking in the wrong database or schema. If you are using management studio, sometimes the wrong database can be selected in the dropdown next to the execute button, and if you don't use the fully qualified name of the view it will try to run using the selected database.