Reference alias (calculated in SELECT) in WHERE clause

You can’t reference an alias except in ORDER BY because SELECT is the second last clause that’s evaluated. Two workarounds: SELECT BalanceDue FROM ( SELECT (InvoiceTotal – PaymentTotal – CreditTotal) AS BalanceDue FROM Invoices ) AS x WHERE BalanceDue > 0; Or just repeat the expression: SELECT (InvoiceTotal – PaymentTotal – CreditTotal) AS BalanceDue FROM … Read more

Getting only Month and Year from SQL DATE

As well as the suggestions given already, there is one other possiblity I can infer from your question: – You still want the result to be a date – But you want to ‘discard’ the Days, Hours, etc – Leaving a year/month only date field SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, <dateField>), 0) AS [year_month_date_field] FROM <your_table> … Read more

Is there any boolean type in Oracle databases?

Not only is the boolean datatype missing in Oracle’s SQL (not PL/SQL), but they also have no clear recommendation about what to use instead. See this thread on asktom. From recommending CHAR(1) ‘Y”https://stackoverflow.com/”N’ they switch to NUMBER(1) 0/1 when someone points out that ‘Y”https://stackoverflow.com/”N’ depends on the English language, while e.g. German programmers might use … Read more