Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i select data from 4 table and data is like that:


(invoice_id) (ino) (block) (Tax) (itemno) (ivalue) (total)
---------- -- ---- --- ------ ------ -----
101 1 false 3 5 121 125
101 1 false 4 5 121 125


problem is that only tax is repeat then all value is twice so, i want all null value of second row value except tax value.

Here is the query to get the above result

SQL
select  distinct tInvoice.*,tChallanMaster.ChallanNo as newChallanNo,SY001.dbo.tCustomer.CustomerName,SY001.dbo.tInvoiceTypeMaster.InvoiceTypeName,tInvoiceAmountDetails.*,tInvoiceTypeDetails.*,SY001.dbo.tItems.Description,SY001.dbo.tPer.PerName,SY001.dbo.tCompany.companyNametoDisplay,SY001.dbo.tCompany.FirstLine,SY001.dbo.tCompany.SecondLine,SY001.dbo.tCompany.CompanyLogo,SY001.dbo.tCompany.TaxDetails from tInvoice left join SY001.dbo.tCustomer on tInvoice.CustomerId=SY001.dbo.tCustomer.CustomerNo left join SY001.dbo.tInvoiceTypeMaster on tInvoice.InvoiceTpye=SY001.dbo.tInvoiceTypeMaster.InvoiceTypeNo left join tInvoiceAmountDetails on tInvoice.InvoiceId =tInvoiceAmountDetails.InvoiceId left join tInvoiceTaxDetails on tInvoice.InvoiceId=tInvoiceTaxDetails.InvoiceId left join tInvoiceTypeDetails on tInvoice.InvoiceId =tInvoiceTypeDetails.InvoiceId  left join SY001.dbo.tItems on tInvoiceTypeDetails.ItemId=SY001.dbo.tItems.ItemNo  left join SY001.dbo.tPer on tInvoiceTypeDetails.Unit=SY001.dbo.tPer.PerNo left join SY001.dbo.tCompany on tInvoice.CompanyId=SY001.dbo.tCompany.CompanyId left join tChallanMaster on tInvoice.InvoiceId =tChallanMaster.InvoiceNo where tInvoice.InvoiceId=10
Posted
Updated 24-Aug-12 3:36am
v4
Comments
ridoy 24-Aug-12 9:09am    
then update those values with null by checking if they are same..
__TR__ 24-Aug-12 9:11am    
Need more information. Post your query which gives the above result.
[no name] 24-Aug-12 9:14am    
select distinct tInvoice.*,tChallanMaster.ChallanNo as newChallanNo,SY001.dbo.tCustomer.CustomerName,SY001.dbo.tInvoiceTypeMaster.InvoiceTypeName,tInvoiceAmountDetails.*,tInvoiceTypeDetails.*,SY001.dbo.tItems.Description,SY001.dbo.tPer.PerName,SY001.dbo.tCompany.companyNametoDisplay,SY001.dbo.tCompany.FirstLine,SY001.dbo.tCompany.SecondLine,SY001.dbo.tCompany.CompanyLogo,SY001.dbo.tCompany.TaxDetails from tInvoice left join SY001.dbo.tCustomer on tInvoice.CustomerId=SY001.dbo.tCustomer.CustomerNo left join SY001.dbo.tInvoiceTypeMaster on tInvoice.InvoiceTpye=SY001.dbo.tInvoiceTypeMaster.InvoiceTypeNo left join tInvoiceAmountDetails on tInvoice.InvoiceId =tInvoiceAmountDetails.InvoiceId left join tInvoiceTaxDetails on tInvoice.InvoiceId=tInvoiceTaxDetails.InvoiceId left join tInvoiceTypeDetails on tInvoice.InvoiceId =tInvoiceTypeDetails.InvoiceId left join SY001.dbo.tItems on tInvoiceTypeDetails.ItemId=SY001.dbo.tItems.ItemNo left join SY001.dbo.tPer on tInvoiceTypeDetails.Unit=SY001.dbo.tPer.PerNo left join SY001.dbo.tCompany on tInvoice.CompanyId=SY001.dbo.tCompany.CompanyId left join tChallanMaster on tInvoice.InvoiceId =tChallanMaster.InvoiceNo where tInvoice.InvoiceId=10
Philip Stuyck 24-Aug-12 12:04pm    
It might be usefull to also post the result you really want.

Why do you want this ? If you're iterating over the data, just remember the last one you read in, and keep grouping until it changes.
 
Share this answer
 
In my opinion, typically if you need to use the keyword DISTINCT, there's something wrong with either the query or the database design. Using DISTINCT should be a rare case and well justified.

Without knowing the design, the data or the requirements, I would suggest you go through the model and invesigate that it properly satisfies the requirements and is well normalized.

One typical problem is that if the 3rd normal form isn't met, the need to use distinct arises in several use-cases. For more information, please see Third normal form[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900