SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Required in row level in Sql server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kond.mohan
Posting Yak Master

India
189 Posts

Posted - 05/04/2013 :  07:06:09  Show Profile  Reply with Quote
hi
i am not able getting data in proper order

i am executing query on ssms for preparing the repott
i am getting loop 49 records i need to get the 7 records.
pls explain process



SELECT distinct
AK.VBELN AS QUOTATION_NUMBER, AK.KNUMV AS DOC_cond ,AP.POSNR AS ITEM,AP.MATNR AS MATERIAL,
AP.KWMENG AS ORDERQTY, AP.ZIEME AS UOM,
KV2.KWERT AS MRP_VAL,
KV3.KWERT AS ASS_VAL
FROM KNA1 K
INNER JOIN VBAK AK ON AK.KUNNR=K.KUNNR
INNER JOIN VBAP AP ON AK.VBELN=AP.VBELN
INNER JOIN KONV KV ON AK.KNUMV=KV.KNUMV AND KV.MANDT=AK.MANDT
INNER JOIN (SELECT DISTINCT KONV.KWERT,KONV.KNUMV,KONV.MANDT FROM KONV WHERE KSCHL='ZMRP' AND KSCHL IS NOT NULL) KV2 ON KV2.KNUMV=KV.KNUMV AND KV2.MANDT=KV.MANDT
inner JOIN (SELECT DISTINCT KONV.KWERT,KONV.KNUMV,KONV.MANDT FROM KONV WHERE KSCHL='ZASS' AND KSCHL IS NOT NULL) KV3 ON KV3.KNUMV=KV.KNUMV AND KV3.MANDT=KV.MANDT
WHERE AK.VBTYP='B'
AND AK.VBELN='0001400829'
AND AP.POSNR=10

0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 247.00
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 689.00
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 750.75
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 1059.50
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 4088.50
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 5148.00
0001400829 0000023315 10 10GREK785-5K 8.000 PIL 380.00 20592.00




mohan

James K
Flowing Fount of Yak Knowledge

3555 Posts

Posted - 05/05/2013 :  21:16:42  Show Profile  Reply with Quote
Perhaps you need to use "SUM(KV3.KWERT) AS ASS_VAL" and group by all the other columns in the select list?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 05/06/2013 :  02:14:16  Show Profile  Reply with Quote
difficult to suggest unless we know how tables are related (it seems to be one to many at the moment) and at what level you need result.
Perhaps you could post some sample data to give us clear idea on it.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.24 seconds. Powered By: Snitz Forums 2000