SQL view nested view is prone to errors

Source: Internet
Author: User

My historical database is another database, used for history Query

Select * From v_b20cpch

Union

Select * from [zmis]. DBO. v_b20cpch

However, this error occurs, and the result misplaces the field.

Later, the nested view is no longer needed. Instead, it is directly written.

Select t1.id, t1.dh, t1.rq, t1.sj, t1.swyy, t1.s30bh, t1.s30mc, t1.s30qc, t1.shdz,
T1.shsj, t1.ch, t1.cx, t1.ry1, t1.shry1, t1.shry2, t1.hjsl, t1.hjmj, t1.hjmj1,
T1.yf, t1.hjje, t1.kclx, t1.bz, t1.gz, t1.gb, t1.gz2, t2.id as t2id, t2.gdh,
T2.ddh, t2.khpo, t2.xh, t2.s20bh, t2.s20mc, t2.s40bh, t2.xx, t2.fs, t2.ms,
T2.s10bh, t2.zxl, t2.zxw, t2.zxh, t2.zxggbz, t2.yc, t2.zxl1, t2.zxw1,
T2.zxh1, t2.pzlx, t2.kw, t2.hb, t2.hbmc, t2.sjph, t2.ws, t2.ddsl, t2.sl,
T2.dxmj, t2.zmj, t2.zmj1, t2.mjgs, t2.mj, t2.czdj, t2.sl1, t2.dj, t2.dj1, t2.je,
T2.bz as t2bz, t2.ddl, t2.cs, t2.shd
From DBO. b20cpck T1 left Outer Join
DBO. b21cpck T2 on t1.dh = t2.dh
Union
Select t1.id, t1.dh, t1.rq, t1.sj, t1.swyy, t1.s30bh, t1.s30mc, t1.s30qc, t1.shdz,
T1.shsj, t1.ch, t1.cx, t1.ry1, t1.shry1, t1.shry2, t1.hjsl, t1.hjmj, t1.hjmj1,
T1.yf, t1.hjje, t1.kclx, t1.bz, t1.gz, t1.gb, t1.gz2, t2.id as t2id, t2.gdh,
T2.ddh, t2.khpo, t2.xh, t2.s20bh, t2.s20mc, t2.s40bh, t2.xx, t2.fs, t2.ms,
T2.s10bh, t2.zxl, t2.zxw, t2.zxh, t2.zxggbz, t2.yc, t2.zxl1, t2.zxw1,
T2.zxh1, t2.pzlx, t2.kw, t2.hb, t2.hbmc, t2.sjph, t2.ws, t2.ddsl, t2.sl,
T2.dxmj, t2.zmj, t2.zmj1, t2.mjgs, t2.mj, t2.czdj, t2.sl1, t2.dj, t2.dj1, t2.je,
T2.bz as t2bz, t2.ddl, t2.cs, t2.shd
From [ztymis3]. DBO. b20cpck T1 left Outer Join
[Ztymis3]. DBO. b21cpck T2 on t1.dh = t2.dh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.