drdre
Starting Member
3 Posts |
Posted - 2011-08-03 : 13:25:55
|
WITH Ranked ( Itemcode, ShortDescription, USERFIELD1, USERFIELD2 ,USERFIELD3,USERFIELD4, ItemStatusDesc, rnk, ItemDesc, ItemContent)AS ( SELECT Itemcode, RSITEM.ItemDesc As ShortDescription, USERFIELD1, USERFIELD2, USERFIELD3, USERFIELD4, ItemStatusDesc, ROW_NUMBER() OVER( PARTITION BY Itemcode ORDER BY Itemcode ), CAST( rssqldb.dbo.RSITEMDESCRIPTION.ItemDesc AS VARCHAR(8000)), CAST( rssqldb.dbo.RSITEMCONTENT.ItemContent AS VARCHAR(8000))FROM rssqldb.dbo.RSITEMINNER JOINrssqldb.dbo.RSITEMDESCRIPTIONON rssqldb.dbo.RSITEM.ItemID = rssqldb.dbo.RSITEMDESCRIPTION.ItemIDINNER JOINrssqldb.dbo.RSITEMCONTENTON rssqldb.dbo.RSITEM.ItemID = rssqldb.dbo.RSITEMCONTENT.ItemIDINNER JOINrssqldb.dbo.RSACCOUNTON rssqldb.dbo.RSITEM.AccountID = rssqldb.dbo.RSACCOUNT.AccountIDINNER JOIN rssqldb.dbo.RSITEMSTATUSON rssqldb.dbo.RSITEM.ItemStatusID= rssqldb.dbo.RSITEMSTATUS.ItemStatusIDWhere rssqldb.dbo.RSITEM.ITEMCode='0000798'), AnchorRanked ( Itemcode,ShortDescription, USERFIELD1, USERFIELD2,USERFIELD3,USERFIELD4,ItemStatusDesc, rnk, ItemDesc, ItemContent )AS ( SELECT Itemcode, ShortDescription, USERFIELD1, USERFIELD2, USERFIELD3, USERFIELD4, ItemStatusDesc, rnk, ItemDesc, ItemContentFROM RankedWHERE rnk = 1), RecurRanked ( Itemcode,ShortDescription, Userfield1,USERFIELD2,USERFIELD3,USERFIELD4,ItemSt atusDesc, rnk, ItemDesc, ItemContent )AS ( SELECT Itemcode, ShortDescription, USERFIELD1, USERFIELD2, USERFIELD3, USERFIELD4, ItemStatusDesc, rnk, ItemDesc, ItemContentFROM AnchorRankedUNION ALLSELECT Ranked.Itemcode, RANKED.ShortDescription, RANKED.USERFIELD1, RANKED.USERFIELD2, RANKED.USERFIELD3, RANKED.USERFIELD4, RANKED.ItemStatusDesc, Ranked.rnk, RecurRanked.ItemDesc + ', ' + Ranked.ItemDesc, RecurRanked.ItemContent + ', ' + Ranked.ItemContentFROM RankedINNER JOINRecurRankedON Ranked.Itemcode = RecurRanked.ItemcodeAND Ranked.rnk = RecurRanked.rnk + 1)SELECT Itemcode, ShortDescription, MAX( ItemDesc ) As LongDescription, MAX(ItemContent) As Content, UserField1, USERFIELD2, USERFIELD3, USERFIELD4, ItemStatusDesc As ItemStatusFROM RecurRankedGROUP BY Itemcode,ShortDescription, UserField1, USERFIELD2,USERFIELD3,USERFIELD4, ItemStatusDesc;The above is the coding that i have done.. but i run into a problem when the ItemDesc field is less populated than the Content field and vise versa. It would duplicate the data in the field till both ItemDesc and ItemContent are the same in length.Any suggestions on how i can correct this.With Jah Jahanything is possible |
|