Skip to content

Instantly share code, notes, and snippets.

@danieleli
Last active August 29, 2015 14:25
Show Gist options
  • Save danieleli/1a62855c95d9fcd2946a to your computer and use it in GitHub Desktop.
Save danieleli/1a62855c95d9fcd2946a to your computer and use it in GitHub Desktop.
ALTER FUNCTION [dbo].[Creative_Grid] (
@start DATETIME,
@end DATETIME,
@clientIds VARCHAR(MAX),
@seId VARCHAR(MAX) = null,
@campaignId VARCHAR(MAX) = null,
@adCategoryId VARCHAR(MAX) = null
)
RETURNS TABLE AS RETURN
(
SELECT
creative_base.*,
fact.*,
onsite.*
FROM
creative_base
JOIN Creative_Fact ( @start, @end, @clientIds, @seId, @campaignId, @adCategoryId ) AS fact
ON creative_base.creativeid = fact.FactCreativeId
LEFT OUTER JOIN Creative_Fact_Onsite ( @start, @end, @clientIds, @seId, @campaignId, @adCategoryId ) AS onsite
ON creative_base.creativeid = onsite.OnsiteCreativeid
WHERE
creative_base.AdStatusID != 3
AND creative_base.AdTypeID = 1
AND creative_base.ClientID in (SELECT * FROM Split(@clientIds, ','))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment