SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT Query problem?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

thudson
Starting Member

United Kingdom
2 Posts

Posted - 01/21/2013 :  14:46:50  Show Profile  Reply with Quote
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.

Edited by - thudson on 01/21/2013 14:59:16

cstokes91
Yak Posting Veteran

USA
59 Posts

Posted - 01/21/2013 :  15:04:30  Show Profile  Reply with Quote
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 :)

Edited by - cstokes91 on 01/21/2013 15:13:58
Go to Top of Page

thudson
Starting Member

United Kingdom
2 Posts

Posted - 01/21/2013 :  15:36:26  Show Profile  Reply with Quote
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 ?


Edited by - thudson on 01/21/2013 15:37:51
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3589 Posts

Posted - 01/21/2013 :  15:41:53  Show Profile  Reply with Quote
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

USA
59 Posts

Posted - 01/21/2013 :  15:43:25  Show Profile  Reply with Quote

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'
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000