create view vw_a as select A_ID, 0 AS [count] from A
如果[count]是表A里的字段,那么把as count 的 count 也加上 []
create view vw_a(A_ID,count) as select A_ID, ISNULL([count],0) AS count from A
--测试:create table tb(id int,[count] int)insert into tb select 1,1create view v_test (id,[count]) as select id,isnull([count],0) [count] from tbselect * from v_test/* id count ------------ 1 1 */drop view v_test drop table tb
create view vw_a as select A_ID, ISNULL([count],0) AS [count] from A
还没解决了 Msg 207, Level 16, State 1, Procedure vw_a, Line 4 Invalid column name 'count'. count不是表的字段 是我要在View里面建的
因为编译通不过. 楼主是不是要获取该表的纪录数,然后返回一个名为COUNT的列?如果是,那就create view vw_a as select A_ID, isnull(count(*),0) as [count] from A group by A_ID
create view vw_a as select A_ID, ISNULL([count],0) AS [count] --count 字段别名与关键字冲突了,需要加[] from A
就是要在view里面多个字段 不是要统计 create view vw_A as select A_ID, ISNULL([count],0) AS [count] from A这样还是不行的 Msg 207, Level 16, State 1, Procedure vw_A, Line 4 Invalid column name 'count'.
select
A_ID, 0 AS [count]
from A
select
A_ID,
ISNULL([count],0) AS count
from A
as
select id,isnull([count],0) [count] from tbselect * from v_test/*
id count
------------
1 1
*/drop view v_test
drop table tb
select
A_ID,
ISNULL([count],0) AS [count]
from A
Msg 207, Level 16, State 1, Procedure vw_a, Line 4
Invalid column name 'count'.
count不是表的字段 是我要在View里面建的
楼主是不是要获取该表的纪录数,然后返回一个名为COUNT的列?如果是,那就create view vw_a as
select
A_ID,
isnull(count(*),0) as [count]
from A
group by A_ID
create view vw_a as
select
A_ID,
ISNULL([count],0) AS [count] --count 字段别名与关键字冲突了,需要加[]
from A
就是要在view里面多个字段
不是要统计
create view vw_A as
select
A_ID,
ISNULL([count],0) AS [count]
from A这样还是不行的
Msg 207, Level 16, State 1, Procedure vw_A, Line 4
Invalid column name 'count'.