agnieszka
agnieszka

Reputation: 15345

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

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"

Upvotes: 2

Views: 7177

Answers (2)

KM.
KM.

Reputation: 103589

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....

Upvotes: 1

cmsjr
cmsjr

Reputation: 59165

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

Upvotes: 12

Related Questions