有没有办法让这个 SQL 更小?
CASE
WHEN @contentType = 'PrimaryBannerItem' THEN
[dbo].[DeathStar_GetContentLink] (@contentId, c.content_id, @pageCollectionId, ISNULL(l.filename, ''))
ELSE
[dbo].[DeathStar_GetContentImagePath](ISNULL(a.mimetype, ''), ISNULL(c.image, ''), ISNULL(l.filename, ''))
END AS [Image],
CASE
WHEN @contentType = 'PrimaryBannerItem' THEN
dbo.DeathStar_GetMetadataValue(c.content_id, @urlMetadataId)
ELSE
[dbo].[DeathStar_GetContentLink](@contentId, c.content_id, @pageCollectionId, ISNULL(l.filename, ''))
END AS Link,
让它看起来更像
CASE
WHEN @contentType = 'PrimaryBannerItem' THEN
[dbo].[DeathStar_GetContentLink](@contentId, c.content_id, @pageCollectionId, ISNULL(l.filename, '')) as [Image]
dbo.DeathStar_GetMetadataValue(c.content_id, @urlMetadataId) as [Link]
ELSE
[dbo].[DeathStar_GetContentImagePath](ISNULL(a.mimetype, ''), ISNULL(c.image, ''), ISNULL(l.filename, '')) as [Image]
[dbo].[DeathStar_GetContentLink](@contentId, c.content_id, @pageCollectionId, ISNULL(l.filename, '')) as [Link]
END
因为如您所见,它使代码更具可读性,减少了使用的行数并避免了冗余。