SELECT DISTINCT A.invname, A.invpinpai, A.invspec, REPLACE(A.invtype, ',', ' ') AS invtype, B.measname, A.pk_invcl, A.pk_corp, A.pk_invbasdoc, F.fullname, E.cbuyer FROM dbo.nw_inv AS A INNER JOIN dbo.v_nw_measdoc AS B ON A.pk_measdoc = B.pk_measdoc INNER JOIN dbo.v_nw_ic_onhandnum AS C ON C.cinvbasid = A.pk_invbasdoc AND C.pk_corp = A.pk_corp INNER JOIN dbo.v_nw_stordoc AS D ON D.pk_stordoc = C.cwarehouseid AND C.pk_corp = D.pk_corp LEFT OUTER JOIN dbo.v_nw_inv_position AS E ON E.pk_invbasdoc = A.pk_invbasdoc LEFT OUTER JOIN dbo.sys_user AS F ON F.Nc_UserID = E.cemployeeid
------解决方案--------------------
SQL code
---索引视图
索引视图是具体化的视图
--创建索引视图
create view 视图名 with schemabinding
as
select 语句
go
---创建索引视图需要注意的几点
1. 创建索引视图的时候需要指定表所属的架构
--错误写法
create view v_f with schemabinding
as
select
a.a,a.b,b.a,b.b
from
a join b
on
a.id=b.id
go
---正确写法:
create view v_f with schemabinding
as
select
a.a,a.b,b.a,b.b
from
dbo.a join dbo.b
on
a.id=b.id
go
2.在创建索引视图的select语句时,不使用*,必须指定具体的列名
--错误写法
create view v_f with schemabinding
as
select
*
from
dbo.a join dbo.b
on
a.id=b.id
go
---正确写法
create view v_f with schemabinding
as
select
a.a,a.b,b.a,b.b
from
dbo.a join dbo.b
on
a.id=b.id
go
3.在创建索引视图的select 语句中,不能存在重复的列名,这个不举例了
4. 只能为索引视图创建唯一聚集索引
--正确的写法
create unique clustered index ix_uniquetb on v_tb
go
--错误的写法
create clustered index ix_uniquetb on v_tb
go
------解决方案-------------------- 可以建立唯一聚集索引。
------解决方案--------------------