Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sub-Qry from Main Qry

Author  Topic 

bkbinani
Starting Member

15 Posts

Posted - 2012-09-28 : 00:24:08
I wish to pick up only Distinct uPartyID from a Trn File with
a date range. I must consider Those UpartyId whose at least any balance b4 startind date or any Transaction within date range.

I had tried with following codes but it does not show Distinct uPartyID instead same uPartyID comes twise or more.

Plz Help.

My Tables: DAT_TRN (Trns Table )
MST_LED (Master Table)

My Codes:

quote:
** -- Target to Picup unique uPartyID
declare @nTotQty numeric(10), @yesno Bit
set @nTotQty = 0
SET @yesno = 0

Select uPartyId,cLedName, @nTotQty as nTotQty, @yesno as yesno
from DAT_trn Join mst_led on uledCode = uPartyID
where dTrnDate between ?m.pdFrom and ?m.pdUpto
UNION
Select uPartyID,cLedName, Sum(nQnty) as nTotQty ,@yesno as yesno
from dat_trn Join mst_led on uledCode = uPartyID
where dTrnDate < ?m.pdFrom
group by uPartyId, cLedName, cMkt_Type, cSymbol, dExpiry, nStrike
Order by cLedName


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-28 : 10:22:01
whats are column in your table? show some sample data and give expected output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bkbinani
Starting Member

15 Posts

Posted - 2012-09-29 : 01:03:16
quote:
Originally posted by visakh16

whats are column in your table? show some sample data and give expected output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Thanx for reply sir. My hats-off 2 u for being a MVP.

dbo.DAT_TRN
Fields: cMkt_type c(5), dtrnDate datetime,UpartyID UID, cSymbol c(15), dExpiry datetime, nQnty number(10) , cTags c(5), nStrike Number(14,4)

dbo.MST_LED
Fields: uLedCode UID, cLedName C(45), iAutoid (i)
(** Here UledCode is PK)

hope this help.
Please sir.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-01 : 11:09:39
hmm..is this sql server? whats c(5) etc? I dont think this is t-sql

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -