ビュー内の各列の行を返すクエリが必要です。ビュー自体。ビュー内の各列(フィールド)の基本テーブルと基本列(フィールド)を返すSQL Server(2005+)クエリ
結果には、現在の行の列の基本表と、結果の中の基底の列(名前が変更された列の列)の名前を示す列のベースフィールドが必要です。任意の計算をベースフィールドの列に含めることができれば、ボーナスになります。
私はこれができるとは思わない。私が間違っている?
以下の例では、 "what goes here"は、basetable列で適切にtable1またはtable2に、basefield列で適切にa、b、またはcに置き換える必要があります。
create table table1 (a int, b int) create table table2 (a int, c int) go create view view1 as select table1.a, table1.b, table2.c from table1 left join table2 on table1.a = table2.a go select * from ( select 'View' objecttype,O.name viewname,'' fieldname,0 column_id,'' typename,'' max_length,'' [precision], '' scale, '' is_identity, 'what goes here' basetable, '' basefield from sys.objects O where O.type='V' and O.[schema_id] = 1 union all select 'Field' objecttype,object_name(C.[object_id]) viewname,C.name fieldname,C.column_id,T.name typename,C.max_length,C.precision,C.scale,C.is_identity, 'what goes here' basetable, 'what goes here' basefield from sys.columns C left join sys.types T on C.user_type_id=T.system_type_id where C.[object_id] in (select O.[object_id] from sys.objects O where O.type='V') ) I where viewname in ('view1') order by viewname, column_id drop view view1 drop table table1 drop table table2
ええ、それはボーナスです:計算されたフィールドの計算でそれが私に戻ってきたらどうですか? SQL Serverがすでに行っている構文解析に基づいた方法があるかどうか疑問に思うだけです。クエリを実行できるということは、これが可能であることを意味します。 –
しかし、ビューを考慮してそれを得る方法は、複数のタブブルの間の結合を持つまっすぐなクエリですか? – Kangkan