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)
 synatx error

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-27 : 21:32:18
Anyone can check ?
----------------------------- this column is workable and ok.
case when trx_acc_amt<1000
then trx_acc_amt/nullif((Sum(
case when salesman_code is null or salesman_code=' ' then 0 else 1 end +
case when salesman_code2 is null or salesman_code2=' ' then 0 else 1 end +
case when salesman_code3 is null or salesman_code3=' ' then 0 else 1 end +
case when salesman_code4 is null or salesman_code4=' ' then 0 else 1 end +
case when salesman_code5 is null or salesman_code5=' ' then 0 else 1 end +
case when salesman_code6 is null or salesman_code6=' ' then 0 else 1 end)),0)
else
trx_acc_amt / 2
end as bonus,

--------- error in this column
convert(varchar, convert(decimal(5,2), 100.0 * (trx_acc_amt)/(bonus)))+'%' as percentof

from xx



gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-27 : 21:36:02
You can't use the alias there
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-28 : 03:10:11
Create view or CTE of this query then use alias name to divide

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -