| Author |
Topic |
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-23 : 06:04:33
|
| Sample DataType # Amt # Trno # DC # Code # SubcodeADV # 1000 # 1 #D # 103625 # ADV # 1000 # 1 #C # 103400 # S1ADV # 2000 # 2 #D # 103625 # ADV # 2000 # 2 #C # 103400 # S2VES # 5000 # 1 #D # 103400 # S1VES # 5000 # 1 #C # 300070 # S1Now I wanna find out the details of Code & Subcode of Type(VES) which does not match with Type ADVExpected result should come with subcode of the other recordADV # 2000 # 2 #D # 103625 # S2Thanks in advanceNirene |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 06:09:17
|
| what about other ones with code 103625 ?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-23 : 06:12:08
|
| Hai, Thanks for the reply and that record(103400) has to be omitted.Nirene |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 06:17:01
|
| nope what about other record of ADV with code 103625 ?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-23 : 06:25:17
|
| That also has to be omitted, only ADV that does not match with VES has to be fetched |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 06:45:15
|
| still not clearhow did S2 come with 103625 for ADV------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-23 : 06:50:16
|
quote: Originally posted by visakh16 still not clearhow did S2 come with 103625 for ADV------------------------------------------------------------------------------------------------------
If possible S2 should be updated using Trno(2) & Type(ADV) out of the selected Data. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-24 : 01:12:57
|
| Hai Visakh, I'm using SQL Server 2000, my details as per your advice I hope.Drop Table #TempCreate Table #Temp (Type Char(3),Amt Real,Trno Int,DC Char(1),Code Char(6),Subcode Varchar(12))Insert Into #Temp Select 'ADV',1000 , 1 ,'D' ,'103625' ,'' Union AllSelect 'ADV',1000 , 1 ,'C' ,'103400' ,'S1' Union AllSelect 'ADV',2000 , 2 ,'D','103625' ,'' Union AllSelect 'ADV',2000 , 2 ,'C','103400','S2' Union AllSelect 'VES',5000 , 1 ,'D' ,'103400' ,'S1' Union AllSelect 'VES',5000 , 1 ,'C' ,'300070','S1'VES stands for Vehicle Sales Invoice and ADV for Credit AdviceI want to fetch all ADV(Credit Advices) which does not have a VES(Vehicle Sales Invoice) which is based on Code & Subcodeas you can see 'VES','103400' ,'S1' has a advice as 'ADV' '103400' ,'S1' so this detail has to to be omitted.First Result which is expected'ADV',2000 , 2 ,'D','103625' ,'' 'ADV',2000 , 2 ,'C','103400','S2'Final result The Subcode 'S2' has to updated into the the result which is fetched 'ADV',2000 , 2 ,'D','103625' ,'S2'I hope the info provided is in detail.RegardsNirene |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 01:23:06
|
| [code]SELECT m.Type,m.Amt,m.Trno,MAX(m.DC) AS DC,MAX(m.Code) AS Code,MAX(m.SubCode) AS SubCode FROM #Temp mLEFT JOIN(SELECT t1.Type,t1.Amt FROM #Temp t1 INNER JOIN #Temp t2 ON t1.Code =t2.Code AND t1.SubCode = t2.SubCode AND t1.Type='ADV' AND t2.Type = 'VES' )mON m.Type=n.TypeAND m.Amt=n.AmtWHERE n.Type IS NULLGROUP BY m.Type,m.Amt,m.Trno [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2010-04-24 : 01:44:56
|
| Visakh thanks a lot it worked fine.alias m changed to nm.type='ADV' just added Nirene |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 07:17:49
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|