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
 Newbie needs help on joining query

Author  Topic 

steveoz32
Starting Member

3 Posts

Posted - 2007-10-11 : 07:22:26
Hi All,

First off sorry for my complete lack of experience with SQL, but I've just started a new position which involved learning SQL. I'm currently looking for a course but in the mean time I just have to try and fumble by doing basic things.

I'm trying to write my first basic select / join statement, and I just can't seem to get it working.

Any help would really be appreciated. It's T-SQL we use btw.

Thanks :)



USE MLSDHeat
GO

select * from dbo.CallLog
where callstatus between 'open'and 'pending'
right outer join dbo.Asgnmnt
on callid = callid
order by callid



--the above returns error Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'right'.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-10-11 : 07:30:23
Books On Line is your best bet to learn how to write basic queries

select a.callid,b.col1,b.col2,b.col3,etc.
from dbo.CallLog a
right outer join
dbo.Asgnmnt b
on
a.callid = b.callid

where a.callstatus IN ('open','pending')

order by a.callid


Jim
Go to Top of Page

steveoz32
Starting Member

3 Posts

Posted - 2007-10-11 : 07:54:24
quote:
Originally posted by jimf

Books On Line is your best bet to learn how to write basic queries

select a.callid,b.col1,b.col2,b.col3,etc.
from dbo.CallLog a
right outer join
dbo.Asgnmnt b
on
a.callid = b.callid

where a.callstatus IN ('open','pending')

order by a.callid


Jim



Spot on thanks very much :) So I had the where statement in the wrong place and the callid field was ambiguous. Got it now.

(sorry about the double post wasn't sure I posted in the right place)
Go to Top of Page
   

- Advertisement -