I am working on a Microsoft Commerce Server 2009 site where we are using the Marketing Manager to serve up ads to a custom Silverlight application. This all works great except that there does not seem to be much in the way of reporting available to make sure that the ads have valid data.
I threw this set of queries together to provide a rolled up view of one ad per row.
I’m sure there are better ways of getting this data, but I haven’t seen it so far. It runs pretty fast.
Ymmv.
Code Snippet
- USE [<Your Database Here>_marketing];
- DECLARE @i_pg_id integer,@u_pg_tag nvarchar(25),@u_pg_description nvarchar(255)
- DECLARE @u_camp_name nvarchar(50), @i_aditem_id integer, @u_campitem_name nvarchar(50),
- @b_campitem_active bit
- DECLARE @i_aditem_weight integer, @dt_campitem_start datetime, @dt_campitem_end datetime,
- @u_size_name nvarchar(50)
- DECLARE @display_type nvarchar(50), @imageheight integer, @imagewidth integer,
- @imageurl nvarchar(1000), @alttext nvarchar(1000), @targeturl nvarchar(1000),
- @textcontent nvarchar(1000), @headline nvarchar(1000)
- DECLARE @u_ct_name nvarchar(50), @u_cp_name nvarchar(50), @text_cpv_value nvarchar(1000)
- DECLARE @u_expr_name nvarchar(100), @ExpressionScope nvarchar(10), @TargetAction nvarchar(10)
- DECLARE @ExpressionCount integer, @Expression1 nvarchar(120), @Expression2 nvarchar(120),
- @Expression3 nvarchar(120), @Expression4 nvarchar(120)
- DECLARE @Results TABLE
- (
- i_pg_id integer,
- u_pg_tag nvarchar(25),
- u_pg_description nvarchar(255),
- u_camp_name nvarchar(50),
- i_aditem_id integer,
- u_campitem_name nvarchar(50),
- b_campitem_active bit,
- i_aditem_weight integer,
- dt_campitem_start datetime,
- dt_campitem_end datetime,
- u_size_name nvarchar(50),
- display_type nvarchar(50),
- imageheight integer,
- imagewidth integer,
- imageurl nvarchar(1000),
- alttext nvarchar(1000),
- targeturl nvarchar(1000),
- textcontent nvarchar(1000),
- headline nvarchar(1000),
- Expression1 nvarchar(120),
- Expression2 nvarchar(120),
- Expression3 nvarchar(120),
- Expression4 nvarchar(120)
- )
- DECLARE curPageGroup CURSOR READ_ONLY FOR
- SELECT [i_pg_id],[u_pg_tag],[u_pg_description]
- FROM [mktg_page_group]
- ORDER BY [u_pg_tag]
- OPEN curPageGroup
- FETCH NEXT FROM curPageGroup INTO @i_pg_id,@u_pg_tag,@u_pg_description
- WHILE (@@FETCH_STATUS = 0)
- BEGIN
- DECLARE curAd CURSOR READ_ONLY FOR
- SELECT mc.[u_camp_name]
- ,ad.[i_aditem_id]
- ,ci.[u_campitem_name]
- ,ci.[b_campitem_active]
- ,ad.[i_aditem_weight]
- ,ci.[dt_campitem_start]
- ,ci.[dt_campitem_end]
- ,ms.[u_size_name]
- FROM [mktg_ad_item] ad inner join [mktg_campaign_item] ci on ad.[i_campitem_id]=ci.[i_campitem_id]
- left outer join [mktg_campaign] mc on mc.[i_camp_id] = ci.[i_camp_id]
- inner join [mktg_creative] mk on ci.[i_creative_id] = mk.[i_creative_id]
- inner join [mktg_creative_size] ms on mk.[i_creative_size_id] = ms.[i_creative_size_id]
- inner join [mktg_page_group_xref] px on ci.[i_campitem_id] = px.[i_campitem_id]
- inner join [mktg_page_group] pg on px.[i_pg_id] = pg.[i_pg_id]
- WHERE ci.[b_campitem_deleted] = 0
- and pg.i_pg_id = @i_pg_id
- ORDER BY ad.[i_aditem_id]
- OPEN curAd
- FETCH NEXT FROM curAd INTO @u_camp_name, @i_aditem_id, @u_campitem_name, @b_campitem_active,
- @i_aditem_weight, @dt_campitem_start, @dt_campitem_end, @u_size_name
- WHILE (@@FETCH_STATUS = 0)
- BEGIN
- SELECT @display_type = '',
- @imageheight = 0,
- @imagewidth = 0,
- @imageurl = '',
- @alttext = '',
- @targeturl = '',
- @textcontent = '',
- @headline = ''
- DECLARE curValues CURSOR READ_ONLY FOR
- SELECT ct.[u_ct_name]
- ,cp.[u_cp_name]
- ,cv.[text_cpv_value]
- FROM [mktg_ad_item] ad inner join [mktg_campaign_item] ci on ad.[i_campitem_id]=ci.[i_campitem_id]
- left outer join [mktg_campaign] mc on mc.[i_camp_id] = ci.[i_camp_id]
- inner join [mktg_creative] mk on ci.[i_creative_id] = mk.[i_creative_id]
- inner join [mktg_creative_type] ct on mk.[i_creative_type_id] = ct.[i_creative_type_id]
- inner join [mktg_creative_property] cp on mk.[i_creative_type_id] = cp.[i_creative_type_id]
- inner join [mktg_creative_property_value] cv on cp.[i_cp_id] = cv.[i_cp_id] and cv.[i_creative_id] = ci.[i_creative_id]
- WHERE ad.[i_aditem_id] = @i_aditem_id
- ORDER BY ad.[i_aditem_id] ,cp.[u_cp_label]
- OPEN curValues
- FETCH NEXT FROM curValues INTO @u_ct_name , @u_cp_name , @text_cpv_value
- WHILE (@@FETCH_STATUS = 0)
- BEGIN
- SET @display_type = @u_ct_name
- IF (@u_cp_name = 'AltText') SET @alttext = @text_cpv_value
- IF (@u_cp_name = 'ClickURL') SET @targeturl = @text_cpv_value
- IF (@u_cp_name = 'clickURL') SET @targeturl = @text_cpv_value
- IF (@u_cp_name = 'ExpandedContent') SET @textcontent = @text_cpv_value
- IF (@u_cp_name = 'Headline') SET @headline = @text_cpv_value
- IF (@u_cp_name = 'Height') SET @imageheight = @text_cpv_value
- IF (@u_cp_name = 'ImageURL') SET @imageurl = @text_cpv_value
- IF (@u_cp_name = 'imgURL') SET @imageurl = @text_cpv_value
- IF (@u_cp_name = 'TargetURL') SET @targeturl = @text_cpv_value
- IF (@u_cp_name = 'RedirectUrl') SET @targeturl = @text_cpv_value
- IF (@u_cp_name = 'text') SET @textcontent = @text_cpv_value
- IF (@u_cp_name = 'TextContent') SET @textcontent = @text_cpv_value
- IF (@u_cp_name = 'Width') SET @imagewidth = @text_cpv_value
- FETCH NEXT FROM curValues INTO @u_ct_name , @u_cp_name , @text_cpv_value
- END
- CLOSE curValues
- DEALLOCATE curValues
- SELECT @ExpressionCount = 0,
- @Expression1 = '',
- @Expression2 = '',
- @Expression3 = '',
- @Expression4 = ''
- DECLARE curExpressions CURSOR READ_ONLY FOR
- SELECT me.[u_expr_name]
- ,CASE me.[b_expr_local]
- WHEN 0 THEN 'Global'
- WHEN 1 THEN 'Local'
- END AS [Expression Scope]
- ,CASE mt.[i_target_action]
- WHEN 1 THEN 'Target'
- WHEN 2 THEN 'Require'
- WHEN 3 THEN 'Exclude'
- WHEN 4 THEN 'Sponsor'
- END AS [Target Action]
- FROM [mktg_ad_item] ad inner join [mktg_campaign_item] ci on ad.[i_campitem_id]=ci.[i_campitem_id]
- left outer join [mktg_campaign] mc on mc.[i_camp_id] = ci.[i_camp_id]
- inner join [mktg_creative] mk on ci.[i_creative_id] = mk.[i_creative_id]
- inner join [mktg_target] mt on mt.[i_campitem_id] = ci.[i_campitem_id]
- inner join [mktg_expression] me on mt.[i_target_expr_id] = me.[i_expr_id]
- WHERE ad.[i_aditem_id] = @i_aditem_id
- OPEN curExpressions
- FETCH NEXT FROM curExpressions INTO @u_expr_name, @ExpressionScope, @TargetAction
- WHILE (@@FETCH_STATUS = 0)
- BEGIN
- SET @ExpressionCount = @ExpressionCount + 1
- IF (@ExpressionCount = 1) SET @Expression1 = @u_expr_name +' / '+@ExpressionScope+' / '+@TargetAction
- IF (@ExpressionCount = 2) SET @Expression2 = @u_expr_name +' / '+@ExpressionScope+' / '+@TargetAction
- IF (@ExpressionCount = 3) SET @Expression3 = @u_expr_name +' / '+@ExpressionScope+' / '+@TargetAction
- IF (@ExpressionCount = 4) SET @Expression4 = @u_expr_name +' / '+@ExpressionScope+' / '+@TargetAction
- IF (@ExpressionCount > 4) SET @Expression4 = @Expression4 + '* '
- FETCH NEXT FROM curExpressions INTO @u_expr_name, @ExpressionScope, @TargetAction
- END
- CLOSE curExpressions
- DEALLOCATE curExpressions
- INSERT INTO @Results (i_pg_id, u_pg_tag, u_pg_description, u_camp_name, i_aditem_id, u_campitem_name,
- b_campitem_active, i_aditem_weight, dt_campitem_start, dt_campitem_end, u_size_name,
- display_type, imageheight, imagewidth, imageurl, alttext, targeturl, textcontent,
- headline, Expression1 , Expression2 , Expression3 , Expression4 )
- VALUES (@i_pg_id, @u_pg_tag, @u_pg_description, @u_camp_name, @i_aditem_id, @u_campitem_name,
- @b_campitem_active, @i_aditem_weight, @dt_campitem_start, @dt_campitem_end, @u_size_name,
- @display_type, @imageheight, @imagewidth, @imageurl, @alttext, @targeturl, @textcontent,
- @headline, @Expression1 , @Expression2 , @Expression3 , @Expression4 )
- FETCH NEXT FROM curAd INTO @u_camp_name, @i_aditem_id, @u_campitem_name, @b_campitem_active,
- @i_aditem_weight, @dt_campitem_start, @dt_campitem_end, @u_size_name
- END
- CLOSE curAd
- DEALLOCATE curAd
- FETCH NEXT FROM curPageGroup INTO @i_pg_id,@u_pg_tag,@u_pg_description
- END
- CLOSE curPageGroup
- DEALLOCATE curPageGroup
- SELECT u_pg_tag AS [Page Group],
- u_pg_description AS [Page Description],
- Expression1 AS [Target Exp 1],
- Expression2 AS [Target Exp 2],
- Expression3 AS [Target Exp 3],
- Expression4 AS [Target Exp 4],
- i_aditem_id AS [Ad Id],
- CASE b_campitem_active
- WHEN 1 THEN 'Active'
- WHEN 0 THEN 'Inactive'
- END AS [Status],
- u_camp_name AS [Campaign],
- u_campitem_name AS [Ad Name],
- i_aditem_weight AS [Weight],
- CONVERT(char(10),dt_campitem_start,126) AS [Start Date],
- CONVERT(char(10),dt_campitem_end,126) AS [End Date],
- u_size_name AS [Display Size],
- display_type AS [Display Type],
- imagewidth AS [Image Width],
- imageheight AS [Image Height],
- imageurl AS [Image URL],
- alttext AS [Alt Text],
- targeturl AS [Target URL],
- textcontent AS [Text Content],
- headline AS [Headline]
- FROM @Results
- ORDER BY [Page Group],[Ad Name]
- GO
No comments:
Post a Comment