2016-12-07 19 views
0

私は以下のコードのためのprofileapplicationの計算カラムを作成したいと思います。関数に基づく計算カラム

Substring(Substring(P.propertyvaluesstring, 
          Charindex('ProfileApplication', P.propertyvaluesstring), 
          Charindex('</ProfileApplication',P.propertyvaluesstring) - 
          Charindex('ProfileApplication',P.propertyvaluesstring)), 
          Charindex('>', Substring(P.propertyvaluesstring, 
          Charindex('ProfileApplication',P.propertyvaluesstring), 
          Charindex('</ProfileApplication',P.propertyvaluesstring) - Charindex('ProfileApplication',P.propertyvaluesstring))) 
      + 1, Len(Substring(P.propertyvaluesstring, 
          Charindex('ProfileApplication', 
          P.propertyvaluesstring), 
          Charindex('</ProfileApplication', 
          P.propertyvaluesstring) - 
          Charindex('ProfileApplication', 
          P.propertyvaluesstring)))) AS 
      ProfileApplication,  

また、ProfileApplicationを計算カラムを使用して他のクエリに使用したいと考えています。私は確信していませんが、可能でしょうか?

SUBSTRING 
     (SUBSTRING 
       (P.ProfileApplication, 
        CHARINDEX('RequisitionStartDate', P.ProfileApplication), 
        CHARINDEX('</RequisitionStartDate',P.ProfileApplication) - 
        CHARINDEX('RequisitionStartDate',P.ProfileApplication) 
        ), 
        CHARINDEX('>', SUBSTRING(P.ProfileApplication, 
        CHARINDEX('RequisitionStartDate', P.ProfileApplication), 
        CHARINDEX('</RequisitionStartDate',P.ProfileApplication) - 
        CHARINDEX('RequisitionStartDate', P.ProfileApplication))) + 1, 
        LEN(SUBSTRING(P.ProfileApplication, 
        CHARINDEX('RequisitionStartDate',P.ProfileApplication), 
        CHARINDEX('</RequisitionStartDate',P.ProfileApplication) - 
        CHARINDEX('RequisitionStartDate',P.ProfileApplication)))) 
+0

テーブル定義を含めることはできますか? –

+0

あなたが私たちに与えたもので質問に答えることは不可能です。一般に、文字列関数を使用してテーブル**内で計算カラム**を作成することができます。しかし、あなたが私たちに与えたものには、この 'P.propertyvaluesstring'のようなものがあります。これは、他のテーブルのカラムを参照しようとしていると思います。私の知識の範囲では、ビュー。しかしそれは別のコンセプトです。 – DVT

答えて

1

と仮定すると、propertyvaluesstringは、計算された列と同じ表に存在します。

これは、あなたが何をする必要があるかである:それらを追加するとき、私は慎重になるように計算列がいつかパフォーマンスに悪影響を与えること

ALTER TABLE <your table name here> 
ADD ProfileApplication AS SUBSTRING(SUBSTRING(propertyvaluesstring, CHARINDEX('ProfileApplication', propertyvaluesstring), CHARINDEX('</ProfileApplication', propertyvaluesstring)-CHARINDEX('ProfileApplication', propertyvaluesstring)), CHARINDEX('>', SUBSTRING(propertyvaluesstring, CHARINDEX('ProfileApplication', propertyvaluesstring), CHARINDEX('</ProfileApplication', propertyvaluesstring)-CHARINDEX('ProfileApplication', propertyvaluesstring)))+1, LEN(SUBSTRING(propertyvaluesstring, CHARINDEX('ProfileApplication', propertyvaluesstring), CHARINDEX('</ProfileApplication', propertyvaluesstring)-CHARINDEX('ProfileApplication', propertyvaluesstring)))) 

注意。

関連する問題