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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sub-Qry from Main Qry
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bkbinani
Starting Member

India
15 Posts

Posted - 09/28/2012 :  00:24:08  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 09/28/2012 :  10:22:01  Show Profile  Reply with Quote
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

India
15 Posts

Posted - 09/29/2012 :  01:03:16  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 10/01/2012 :  11:09:39  Show Profile  Reply with Quote
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
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000