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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT Query problem?

Author  Topic 

thudson
Starting Member

2 Posts

Posted - 2013-01-21 : 14:46:50
I have written a query that says that Verse is an invalid object name, but as you can see from the attached screen shot the table Verse does exist!
Why does it not recoqnise this table?

Your help would be appreciated, as I am a relatively new programmer

P.S. updated image to show fields in tables.

cstokes91
Yak Posting Veteran

72 Posts

Posted - 2013-01-21 : 15:04:30
There is an unnecessary comma after the fourth column...

Check into alias, too.


Select v.ID
,v.greeting
,v.mid
,v.edi

from verses.dbo.verse v
inner join verses.dbo.events e ON e.edi = v.edi


etc, etc

The cleaner your code is the easier it will be to proofread :)
Go to Top of Page

thudson
Starting Member

2 Posts

Posted - 2013-01-21 : 15:36:26
Thanks for spotting my silly mistake with the comma.
I have used aliases as suggested and it works!
However I want to now link and include the other Event field in the output (Event_Type) and would also like to do an inner join with the Event_Sub table to filter this table by Mid value and also show the text field (Event_Sub_Type).

Could you give me some tips on how to do this please ?

Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-01-21 : 15:41:53
Add the columns from Events table that you want to the select list. To get columns from Event_Sub table, join that table also. So, adding on to cstokes code, it would be like this:
SELECT v.ID,
v.greeting,
v.mid,
v.eid,
e.Event_Type,
s.Event_Sub_Type
FROM verses.dbo.verse v
INNER JOIN verses.dbo.events e
ON e.eid = v.eid
INNER JOIN verses.dbo.Event_Sub s
ON s.Eid = e.Eid;
Go to Top of Page

cstokes91
Yak Posting Veteran

72 Posts

Posted - 2013-01-21 : 15:43:25
[code]
Select v.ID
,v.greeting
,v.mid
,v.edi
,e.event_type
,es.event_sub_type

from verses.dbo.verse v
inner join verses.dbo.events e ON e.edi = v.edi
inner join verses.dbo.event_sub es ON es.edi = v.edi -- assuming there is an edi column in this table

where es.mid_value = 'coconut'
[/code]
Go to Top of Page
   

- Advertisement -