Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question About Views

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-11-09 : 15:39:53
I've never worked with views in SQL before, but I'm trying to select one column from the view, somename.customername. When i try to query for:

select somename.customername from dbo.vw_myview 

i get this error:

The multi-part identifier "somename.customername." could not be bound.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-09 : 15:45:42
select customername from dbo.vw_myview

Or: select vw_myview.customername from dbo.vw_myview

Even if "somename" is referenced in the view, you can not refer to it when you call the view.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-09 : 15:47:50
select XXXX.customername from dbo.vw_myview AS XXXX
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-11-09 : 16:48:32
I tried:

select vw_myview.customername from dbo.vw_myview
and
select vw_myview.somename.customername from dbo.vw_myview

but I get "Invalid column name...."

When i do "select * from vw_myview somename.customername" somename.customername is in there.
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-11-09 : 16:49:57
quote:
Originally posted by Kristen

select XXXX.customername from dbo.vw_myview AS XXXX



It still does not work when I derive it.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:08:42
Sounds like there's actually a column called somename.customername...bad practice.

In that case:

SELECT [somename.customername] FROM vw_myView;
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:13:11
By the way, if that doesn't resolve it for you, post the view definition please.
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-11-09 : 17:21:46
quote:
Originally posted by russell

Sounds like there's actually a column called somename.customername...bad practice.

In that case:

SELECT [somename.customername] FROM vw_myView;



That doesn't work either....
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:25:03
Post the DDL. We're just guessing without it.
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-11-09 : 17:27:41
quote:
Originally posted by russell

Sounds like there's actually a column called somename.customername...bad practice.

In that case:

SELECT [somename.customername] FROM vw_myView;



I'm sorry that actually did work with the brackets! Thanks so much!
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:54:40
You're welcome
Go to Top of Page
   

- Advertisement -