Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
The Stored Procedure below returns article attributes for my articles (tblArticleAttribute). This works fine IF NOT tblArticleAttribute.Content is empty, then it returns all templatedefinitions with the Content. But, if the Content is empty, it also has to return all template definitions, but with the content fields empty (now it returns nothing). This is because I bind this information to a dynamic form, and if (example) the title or ingress is empty the textfields (definitions) should be shown with no text. Then the user can fill inn text an save it.----------------------------------Here is the SQL:----------------------------------SELECT tblTemplateDefinition.[Name] as TemplateDefinitionName, tblTemplateDefinition.HelpText as TemplateDefinitionHelpText, tblArticleAttribute.[Content], tblArticle.Id AS ArticleId, tblTemplateDefinition.Id AS TemplateDefinitionIdFROM tblTemplateDefinitionLEFT OUTER JOIN tblArticleAttribute ON tblTemplateDefinition.Id = tblArticleAttribute.TemplateDefinitionIdINNER JOIN tblArticle ON tblArticleAttribute.ArticleId= tblArticle.IdWHERE tblArticle.Id = @ArticleId----------------------------------Here is the tables:----------------------------------tblArticle:id | NametblArticleAttributeTemplateDefinitionId | ArticleId | ContenttblTemplateId | NametblTemplateDefinitionId | TemplateId | TemplateDefinitionId |Name | HelpText
Ifor
Aged Yak Warrior
700 Posts
Posted - 2007-06-08 : 06:36:49
Try:
SELECT D.[Name] as TemplateDefinitionName ,D.HelpText as TemplateDefinitionHelpText ,AA.[Content] ,AA.ArticleId ,D.[Id] AS TemplateDefinitionIdFROM tblTemplateDefinition D LEFT JOIN tblArticleAttribute AA ON D.[Id] = AA.TemplateDefinitionId -- The following needs to be here and not the WHERE clause to keep the LEFT JOIN. AND AA.ArticleId = @ArticleId
webressurs
Starting Member
5 Posts
Posted - 2007-06-08 : 07:23:01
Thank you, that worked!!!WebRessurs<a href="http://www.webressurs.no">www.WebRessurs.no</a>