1

I'm trying to cast a line in a (Teradata) SQL query so I can get decimals:

 (SUM((vndr_po_ln_vb.mnfst_qty - vndr_po_ln_vb.rcvd_qty)))/(CAST(COUNT(DISTINCT vndr_po_vb.vndr_po_num)) AS DECIMAL(3,2))  AS "Average Damaged Cases per PO"

However, it seems that it it throwing back an error:

Syntax error: expected something between ')' and ')'.

Am I correctly casting this line of code?

Felix Reyes
  • 19
  • 1
  • 1
  • 5

1 Answers1

0

You got too many parens and in the wrong places:

SUM(vndr_po_ln_vb.mnfst_qty - vndr_po_ln_vb.rcvd_qty)
/ CAST(COUNT(DISTINCT vndr_po_vb.vndr_po_num) AS DECIMAL(3, 2)) AS "Average Damaged Cases per PO"

But this will fail if the count returns more than 10.

dnoeth
  • 59,503
  • 4
  • 39
  • 56