开发者

Invalid Column Name when using T-SQL column alias

I'm getting started with T-SQL, but appear to be misunderstanding the column alias concepts. I've tried searching for a answer to this without success, though I'm sure it must be something very simple to a more experienced developer. I'm using SQL Server 2008.

select FirstName as nick
from [Dev].[dbo].[Name]
where nick like '%et%'
order by nick desc

Error:

Msg 207, Level 16, State 1, Line 2 Invalid column name 'nick'.

How do I make开发者_如何学运维 this work?


select FirstName as nick
from [Dev].[dbo].[Name]
where FirstName like '%et%' -- There is no such column "nick" in your table
order by 1 desc


This should do it.

SELECT FirstName as nick
FROM Dev.dbo.Name
WHERE FirstName like '%et%'
ORDER BY FirstName DESC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜