Skip to content
Advertisement

Ambiguous column name ‘Created_Date’?

I utilize SQL SSMS. Due to the following, SQL prompts error. After I utilized the same script with many other inner joins the following error remains. I have tried to modify my script, and I keep getting the same messages:

[My script]

Advertisement

Answer

You have:

But the error message is clear: more than one table in your query has a column named Created_Date. So, you need to use the table aliases you created to tell SQL Server which one you mean. Presumably it is from dbo.invoices, so:

Though in is also a poor name choice for an alias because, like double, it is a reserved word/keyword and at the very least will light up in various editors or, in some contexts, cause a syntax error.

More importantly:

This is much more efficiently written as:

It’s a few extra characters, I know, but that at least has a shot of using an index.

Also, if you traverse the opposite way (oldest category to newest), you don’t have to handle the BETWEEN scenario at all, because the first scenario that matches will render the rest of the comparisons no-ops:

You could also simplify it by:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement