建两个视图啊,一个对应ifcom=0,另一个对应incom=1视图是建好后,可以一直用的,直至你drop它。楼主总不会需要时常去动态创建这些视图吧

解决方案 »

  1.   

    用UNION ALL把两个查询拼起来不行么?
      

  2.   

    select A.AId,B.CId,C.Cname,C.CProperty
    from A,B,C
    where A.AId = B.AId and B.CId = C.CId and (A.AId = '0' or A.AId = '1')
      

  3.   

    笔误:
    select A.AId,B.CId,C.Cname,C.CProperty
    from A,B,C
    where A.AId = B.AId and B.CId = C.CId and (A.IfCom = '0' or A.IfCom = '1')
      

  4.   

    原本视图的变化,仅仅是对应于相应表的变化。而现在楼主是要根据条件生成不同视图,也可以说成是这张视图的使用仅限当次查询,查询后就将其DROP掉,因为当下一次查询时可能会有另一个条件,因此需要重新创建一个新的视图。
      

  5.   

    为什么不可以根据条件建立视图?----------------------------------------------
    关于这个问题不是说不可以,当然可以。
    只是以楼主题目中的要求来看,这种操作是毫无意义的视图的创建不是为了某一次特定查询而创建的。
    按楼主的要求,应该是用动态SQL为佳。
      

  6.   

    1 How Views Are Used 
    Views provide a means to present a different representation of the data that resides within the base tables. Views are very powerful because they allow you to tailor the presentation of data to different types of users. 2 Views are often used 
    to provide an additional level of table security by restricting access to a predetermined set of rows and/or columns of a table 
    For example, Figure 8-5 shows how the STAFF view does not show the SAL or COMM columns of the base table EMP. to hide data complexity 
    For example, a single view might be defined with a join, which is a collection of related columns or rows in multiple tables. However, the view hides the fact that this information actually originates from several tables. to simplify commands for the user 
    For example, views allow users to select information from multiple tables without actually knowing how to perform a join. to present the data in a different perspective from that of the base table 
    For example, the columns of a view can be renamed without affecting the tables on which the view is based. to isolate applications from changes in definitions of base tables 
    For example, if a view's defining query references three columns of a four column table and a fifth column is added to the table, the view's definition is not affected and all applications using the view are not affected. to express a query that cannot be expressed without using a view 
    For example, a view can be defined that joins a GROUP BY view with a table, or a view can be defined that joins a UNION view with a table. to save complex queries 
    For example, a query could perform extensive calculations with table information. By saving this query as a view, the calculations can be performed each time the view is queried. 
      

  7.   

    所以说建两个视图啊,一个对应ifcom=0,另一个对应incom=1因为一张视图怎么可能存在变化的条件。如果条件变化了,就成了另一个视图了
      

  8.   

    如创建视图(包含ifcom=1和=0的所有数据)
    select * from 视图 where ifcom=1;