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 2000 Forums
 SQL Server Development (2000)
 Optional column selection

Author  Topic 

rlull
Starting Member

39 Posts

Posted - 2007-06-19 : 12:44:33
Here is my current select statement:

SELECT Documents.*, Categories.Category, PlayerRoles.RoleName, Players.FirstName + ' ' + Players.LastName as PlayerName
FROM Documents
JOIN Categories
ON Documents.CatId = Categories.CatId
JOIN PlayerRoles
ON Documents.RoleId = PlayerRoles.RoleId
JOIN Players
ON Documents.PlayerId = Players.PlayerId
WHERE Documents.DocId = 13
ORDER BY Documents.DocName

However, sometimes there is not a PlayerId (which means no PlayerName either) associated with a document so I need to be able to skip the Players JOIN if the PlayerId = 0. How do I do this? Thanks.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-06-19 : 12:45:54
only with properly parametrized dynamic sql.

or have another procedure.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

cvraghu
Posting Yak Master

187 Posts

Posted - 2007-06-19 : 13:09:53
Use Outer join on Player related tables to fetch record from other tables even when player id is 0.
Go to Top of Page
   

- Advertisement -