Last post Oct 26, 2018 10:51 AM by PatriceSc
Oct 26, 2018 10:30 AM|JagjitSingh|LINK
What is wrong in the below query. It is saying Target invalid column name . I have written below code in function
Select @Lowest= SUM(Target) FROM (Select Top 10 Target from [test] order by Target Asc)
Oct 26, 2018 10:51 AM|PatriceSc|LINK
It usually means that the column name can't be found in the table (usually because the column is not named this way).
The strange thing is that I would expect another error as it is mandatory to give subqueries an alias name (so that you can qualify the column name later if needed) :
should work. If you still have the same error double check the column is named this way. Ah or try perhaps [Target] in case it would be a conflict with a keyword ?
Edit: tested and confirmed. If I change the column name to Something else than the Target column I created I have :
Invalid column name 'Targetx'.
If I test your code with an existing column name I have :
Incorrect syntax near ')'. -- This is because an alias name is expected after the subquery.