We help IT Professionals succeed at work.

non stop tSQL problems today

dbaSQL
dbaSQL asked
on
381 Views
Last Modified: 2008-02-01
please know this is urgent, any assistance really is very appreciated
this statement herein does a simple quantity summation by symbol, for each userid/acctid

SELECT Symbol,UserId, AcctId,
LTRIM(RTRIM(LEFT(CONVERT(char(16),CAST(SUM(CASE WHEN side = 'b' THEN quantity ELSE 0 END) AS MONEY), 1), 13))) AS Buys,
LTRIM(RTRIM(LEFT(CONVERT(char(16),CAST(SUM(CASE WHEN side = 's' THEN quantity ELSE 0 END) AS MONEY), 1), 13))) AS Sells
FROM ........ WITH (NOLOCK)
WHERE (TradeTime >= CONVERT(char(10), GETDATE() - 1, 101) + ' 17:00')
GROUP BY Symbol,UserID,AcctID
ORDER BY Symbol,UserID,AcctID

sample resultset:

symbol/userid/acctid/buys/sells
CCC      GGGGGG      AAAA      100      10
CCC      GGGYYY      AAAA      200      20
CCC      GGGYYY      AAAA      300      30
DDD      HHHHH      AAAA      400      40
DDD      HHHYYY      AAAA      500      50
....
..

i need to add another grouping.  i need to net the symbol, too.   so, it would be similar to this:

CCC     660     60                                                    <<<<THIS IS JUST A TOTAL QUANTITY LINE PER SYMBOL
    CCC      GGGGGG      AAAA      100      10         <<<<THIS IS TOTAL QUANTITIES BOUGHT/SOLD PER SYMBOL, FOR EACH USERID/ACCTID
    CCC      GGGYYY      AAAA      200      20
    CCC      GGGYYY      AAAA      300      30
DDD      990          
    DDD      HHHHH      AAAA      400      40
    DDD      HHHYYY      AAAA      500      50
   
please do let me know what you think, this is very important



Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
i swear to you, matthewspatrick, i was just now trying the same darned thing.  UNIONing the NULLs w/my dataset.
yours looks a little more rounded than mine
i'll let you know shortly

Author

Commented:
wow.  i wish i had finished my attempt before opening this inquiry.  sometimes i feel like i'm out here far too much.
but...regardless...it worked beautifully.  thank you very, very much
CERTIFIED EXPERT
Top Expert 2010

Commented:
dbaSQL,

Glad to help :)

Regards,

Patrick

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.