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.
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 programmerP.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.edifrom verses.dbo.verse v inner join verses.dbo.events e ON e.edi = v.edi etc, etcThe cleaner your code is the easier it will be to proofread :) |
|
|
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 ? |
|
|
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_TypeFROM 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; |
|
|
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_typefrom verses.dbo.verse v inner join verses.dbo.events e ON e.edi = v.ediinner join verses.dbo.event_sub es ON es.edi = v.edi -- assuming there is an edi column in this tablewhere es.mid_value = 'coconut'[/code] |
|
|
|
|
|
|
|