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 2005 Forums
 Transact-SQL (2005)
 JOIN

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-05-01 : 11:58:13
Hello,

I am creating a record set as follows:

DECLARE @tArticles TABLE (PostId UNIQUEIDENTIFIER)
INSERT INTO @tArticles
SELECT a.ArticleId
FROM Articles a

SELECT
c.ArticleID,
c.CommentID,
c.CommentText,
c.CommentAuthorId
FROM @tArticles ta
INNER JOIN Comments c ON ta.ArticleId = c.ArticleID

Now for each comment I want to get the author name and email from the table users (Every comment has an author). I did the following:

SELECT
c.ArticleID,
c.CommentID,
c.CommentText,
c.CommentAuthorId,
u.Username,
u.Useremail
FROM @tArticles ta
INNER JOIN Comments c ON ta.ArticleId = c.ArticleID
INNER JOIN Users u ON c.CommentAuthorId = u.UserId

Can I do this?
"INNER JOIN Users u ON c.CommentAuthorId = u.UserId"

Thank you,
Miguel

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-01 : 12:02:24
Yes. You can do it.

Are you getting any error?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-05-01 : 12:19:31
I was getting an error on my procedure END. I though it was because of this ... i wasn't sure if I could do it. But know I found the error was somewhere else.

I don't understand why SQL sometimes gives me the error on the code line and others on END line.

Thank You,
Miguel
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-01 : 16:59:22
It depends.
First of all what the error really says.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -