use cursors and try this....

Vasanthakumar D replied to felicity taylor at 05-Jul-08 04:49

Hi,

try the below one....

DECLARE details_cursor CURSOR FOR

SELECT purchase.purchaseitem, purchase.purchaseprice, purchase.purchasenumber, sales.saleitem, sales.saleprice, sales.salenumber
FROM purchase INNER JOIN sales ON purchase.purchaseitem=sales.saleitem;
UNION ALL
SELECT purchase.purchaseitem, purchase.purchaseprice, purchase.purchasenumber, sales.saleitem, sales.saleprice, sales.salenumber
FROM purchase LEFT JOIN sales ON purchase.purchaseitem=sales.saleitem
WHERE (((sales.saleitem) Is Null));
UNION ALL
SELECT purchase.purchaseitem, purchase.purchaseprice, purchase.purchasenumber, sales.saleitem, sales.saleprice, sales.salenumber
FROM purchase RIGHT JOIN sales ON purchase.purchaseitem = sales.saleitem
WHERE (((purchase.purchaseitem) Is Null))

declare @PurchaseName varchar(100)

decalre @PurchaseNo int

declare @PurchasePrice int

declare @SaleName varchar(100)

decalre @SaleNo int

declare @SalePrice int

declare @Count int

create table tempTable (PurchaseName varchar(100), PurchaseNo int, PurchasePrice int, SaleName varchar(100), SaleNo int, SalePrice int)

OPEN details_cursor


FETCH NEXT FROM details_cursor into @PurchaseName, @PurchaseNo, @PurchasePrice, @SaleName, @SaleNo, @SalePrice

insert into tempTable  select @PurchaseName as 'PurchaseName',  @PurchaseNo as 'PurchaseNo', @PurchasePrice as 'PurchasePrice', @SaleName as 'SaleName', @SaleNo as 'SaleNo', @SalePrice  as 'SalePrice'

WHILE @@FETCH_STATUS = 0
BEGIN

     FETCH NEXT FROM details_cursor into @PurchaseName, @PurchaseNo, @PurchasePrice, @SaleName, @SaleNo, @SalePrice

select @Count  = count(*) from temptable where PurchaseName = @PurchaseName and PurchaseNo = @PurchaseNo, PurchasePrice = @PurchasePrice

if(@Count > 0)

begin

          @PurchaseName = NULL

         @PurchaseNo = NULL

         @PurchasePrice = NULL

end

insert into tempTable  select @PurchaseName as 'PurchaseName',  @PurchaseNo as 'PurchaseNo', @PurchasePrice as 'PurchasePrice', @SaleName as 'SaleName', @SaleNo as 'SaleNo', @SalePrice  as 'SalePrice'

END

CLOSE details_cursor

DEALLOCATE details_cursor  

select * from tempTable

drop table tempTable



Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  Full joins and Null Fields - felicity taylor  04-Jul-08 07:52 7:52:10 AM
      use cursors and try this.... - Vasanthakumar D  05-Jul-08 04:49 4:49:09 AM
View Posts

promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   


"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class