开发者

Why Select 77C works and not C77 in Sql

If I write select 77C the output is

C
77

But if I write

select C77

The output is Msg 207, Level 16, State 1, Line 1 Invalid column name 'C77'.

Why is the behavi开发者_如何学编程our?


Your DBMS will translate

select 77C

By

select 77 AS C

But it can't translate select C77 because it doesn't mean anything to him.


77 is a literal number so can be selected on its own, for me MSSQL assumes the trailing C is an alias so I get the results you do.

For C77, C is not a valid literal & 77 is not a valid alias so it fails, these for example would work;

select 1 as C into #t
select C[77] from #t

select 'C'[77] 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜