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
 How can I write this...

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-06-22 : 15:59:44
Count(Cos)
from t16pendall
where mft_posn1_cd=B or D) or mft_pos1_cd=A and aged_alien_rsw=y
and cos not in t16pendmvt table

Count cos from T16pendmvt table
where mvt_typ=R and mvt_loc not like 'R, S, V

Count Cos from T16pendmvt table
where mvt_typ='t'

How could I write them all together as a subquery?

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-06-22 : 23:32:59
People cannot read your mind, so post your code and clear specs if you really want help. Please post real DDL and not narrative or your own personal programming language. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. Please tell us what SQL product and release you are using. Tell us if you can change the DDL or if you are stuck with it.

The code you posted is not even close to SQL. Try again



--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 04:17:16
Something like this

sum(case when (mft_posn1_cd in (B,D) or mft_pos1_cd=A and aged_alien_rsw=y then 1 else 0 end) as col1,
sum(case when mvt_typ=R and mvt_loc not in ('R', 'S', 'V') then 1 else 0 end) as col2,
etc



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -