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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 How to divide by a total from an alias column

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-27 : 20:52:23
Dear Sir, Anyone can help me ?

When I run this query have prompt error .

------- error in sum(trx_dat.item_Qty)=1

case when trx_hdr.trx_acc_amt<1000 and sum(trx_dat.item_qty) = 1
then
trx_hdr.trx_acc_amt/total_counter
else
trx_hdr.trx_acc_amt/nullif((Sum(
case when trx_hdr.salesman_code is null or trx_hdr.salesman_code=' ' then 0 else 1 end +
case when trx_hdr.salesman_code2 is null or trx_hdr.salesman_code2=' ' then 0 else 1 end +
case when trx_hdr.salesman_code3 is null or trx_hdr.salesman_code3=' ' then 0 else 1 end +
case when trx_hdr.salesman_code4 is null or trx_hdr.salesman_code4=' ' then 0 else 1 end +
case when trx_hdr.salesman_code5 is null or trx_hdr.salesman_code5=' ' then 0 else 1 end +
case when trx_hdr.salesman_code6 is null or trx_hdr.salesman_code6=' ' then 0 else 1 end)),0)

end as "????????? / ????1000??2????1000????"

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-27 : 21:37:27
Post your whole query and the error messages
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-28 : 03:05:57
You cannot divide by using alias column directly. If requires use CTE.

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -