Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid "IS NOT NULL" part of T-SQL statement

Tags:

t-sql

What is wrong with this statement??

SELECT ID, datediff("mi", Start, End) as Total 
FROM TimeTable
WHERE Total is not null

I get an error "Invalid column name"

like image 554
agnieszka Avatar asked Dec 05 '25 17:12

agnieszka


2 Answers

Reference the expression, not the alias.

SELECT ID, datediff("mi", Start, [End]) as Total 
FROM TimeTable
WHERE datediff("mi", Start, [End])  is not null

EDIT, updated to prevent syntax error for usage of END

like image 73
cmsjr Avatar answered Dec 09 '25 20:12

cmsjr


Don't use reserved words like "End" as table or column names! Use something like TaskStart/TaskEnd or JobStart/JobEnd or StartDate/EndDate, you'll thanks me everytime you don't have to go back and add [] around your table/column names....

like image 32
KM. Avatar answered Dec 09 '25 19:12

KM.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!