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.
| Author |
Topic |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2012-01-31 : 15:14:59
|
| Hi i need a case on inner join as below not sure the best way of doing this??SELECT *FROM Revisions rCASE WHEN @Preview = 0INNER JOIN RevisionsPreview rl on rl.RevisionId = r.IdELSEINNER JOIN RevisionsLive rl on rl.RevisionId = r.Id |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2012-01-31 : 15:19:36
|
| How about creating 2 views. 1 with a join to preview and the other with a join to live. Then test the value of @preview and decide which view to select from?Duane. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-31 : 15:26:23
|
| one way is to use union all------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2012-01-31 : 15:38:53
|
| i cant use views as i need sql to page my results this is the full spSELECT r.Id, r.PageId, r.Content, p.PublishStartDate, p.PublishEndDate, r.CreatedDate, r.CreatedBy, r.Teaser,p.Title, pt.FileLocation as PageTemplate, p.MetaKeywords, p.MetaDescription, u.AliasUrl,ROW_NUMBER() OVER(ORDER BY t.Ordinal desc) AS rownuminto #tmp_tblFROM Revisions rCASE WHEN @Preview = 0INNER JOIN RevisionsPreview rl on rl.RevisionId = r.IdELSEINNER JOIN RevisionsLive rl on rl.RevisionId = r.IdINNER JOIN Pages p on p.Id = r.PageIdINNER JOIN PageTemplates pt on pt.Id = r.TemplateIdINNER JOIN PageToTree ptt ON ptt.PageId = p.IdINNER JOIN Tree t on t.Id = ptt.TreeIdINNER JOIN UrlAlias u ON u.TreeId = t.IdWHERE t.ParentId = @TreeId and p.IsActive = 1AND (PublishStartDate is null or PublishStartDate <= GETDATE())AND (PublishEndDate is null or PublishEndDate > GETDATE())CREATE UNIQUE CLUSTERED INDEX idx_uc_rownum ON #tmp_tbl(rownum) SELECT Id, PageId, Content, PublishStartDate, PublishEndDate, CreatedDate, CreatedBy, Teaser, Title, PageTemplate, MetaKeywords, MetaDescription, AliasUrl FROM #tmp_tbl WHERE rownum BETWEEN (@CurrentPage-1)*@PageSize+1 AND @CurrentPage*@PageSize |
 |
|
|
|
|
|
|
|