question

camrenchetty19 avatar image
camrenchetty19 asked

selecting from a view

Hi guys, urgently need your help. I am trying to select data from a view but it always returns no values...Is there any way that i can retrieve data from a view? Thanks
viewsexport-data
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sp_lock avatar image sp_lock commented ·
Are you able to script the view to see what tsql is used? Then try to run the actual code.
0 Likes 0 ·
Fatherjack avatar image
Fatherjack answered
So long as there is data in the tables referenced by the view that you have permission to see then selecting from a view will return results. you will need to investigate the permissions you are working under and the base tables that the view references
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
...assuming the VIEW definition doesn't include something like WHERE 1=0 (or some other impossibility...)
1 Like 1 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
indeed, and the same goes for the outer SELECT statement.
0 Likes 0 ·
eghetto avatar image eghetto commented ·
yeah, SELECT TOP 0 can also ruin your whole day... ;)
0 Likes 0 ·
Grant Fritchey avatar image
Grant Fritchey answered
Remember, a view does not store data (with the exception of materialized views which are basically tables). It's just a T-SQL statement. If the T-SQL statement in the view does not return data, then you can't get data out of it. While views act like tables as far as T-SQL is concerned, please don't confuse that behavior with actual data storage. There is no data within a view.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.