私は現在、何百万ものレコードを取得しているビューを持っており、単一の特定のアカウント番号までフィルタリングしたいと考えています。私は現在、アカウント番号(使いやすさ)でフィルターを使って新しいカスタムビューを作成したいと考えています。ビューからのSQL Serverのフィルタデータ
これは私がそれを行っている方法です:[口座番号] = '1000'
VIEW_NAME FROM
SELECT *これは私が期待まさに私に与えます。ただし、VIEW_NAME_1000という新しいビューを作成してもう1つの変更を加えたい場合は、既存の日付フィールドに基づいて月の列を作成したいと考えています。
私はこれを試してみました:私はT1を必要に応じて
CASE
WHEN(MONTH(T1.[TRX Date]) = 1) THEN "January " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 2) THEN "February " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 3) THEN "March " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 4) THEN "April " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 5) THEN "May " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 6) THEN "June " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 7) THEN "July " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 8) THEN "August " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 9) THEN "September " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 10) THEN "October " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 11) THEN "November " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 12) THEN "December " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
END as 'Trx Month'
私は知りません。特に私が既に存在するビューからデータを取り出すだけなので、参照してください。
ここに私のSQLクエリ全体がありますが、期待どおりに動作していません...どこに私のケースを置いてもエラーメッセージが表示されます。
CREATE VIEW [dbo].[VIEW_NAME_1000] AS
SELECT [Journal Entry], Series, [TRX Date], [Account Number], [Account Description], [Credit Amount], [Debit Amount], [Account Category Number],
[Account Description from Account Master], [Account Index], [Account Type], [Account Type from Account Master], Active, [Adjust for Inflation], [Back Out JE],
[Balance For Calculation], [Balance For Calculation from Account Master], [Batch Number], [Batch Source], [Closed Year], [Conversion Method], [Correcting JE],
CorrespondingUnit, [Created Date], [Currency ID], [Currency Index], [DTA Control Number], [DTA GL Status], [DTA Index], [DTA TRX Type], [Decimal Places],
[Decimal Places from Account Master], [Denomination Exchange Rate], Description, [Document Date], [Document Status], [Error State], [Exchange Date],
[Exchange Rate], [Exchange Table ID], [Fixed Or Variable], [Fixed Or Variable from Account Master], [Historical Rate], [History TRX], [History Year], ICDists, [IC TRX],
[Inflation Equity Account Index], [Inflation Revenue Account Index], [Intercompany ID], [Last Date Edited], [Last User], [Line Status], [MC Transaction State],
[Main Account Segment], [Modified Date], [Note Index], [Note Index from Account Master], [Open Year], [Original JE], [Originating Company ID],
[Originating Control Number], [Originating Credit Amount], [Originating DTA Series], [Originating Debit Amount], [Originating Document Number],
[Originating Journal Entry], [Originating Master ID], [Originating Master Name], [Originating Posted Date], [Originating Sequence Number], [Originating Source],
[Originating TRX Source], [Originating TRX Type], [Originating Type], [Period ID], [Period Posting Number], [Approval User ID], [Approval Date], [Polled Transaction],
[Post Inventory In], [Post Payroll In], [Post Purchasing In], [Post Sales In], [Posting Number], [Posting Type], [Posting Type from Account Master], [Printing Status],
[Quick Offset], [Rate Calculation Method], [Rate Type ID], [Recurring TRX], [Recurring TRX Sequence], Reference, [Reversing Closed Year], [Reversing Date],
[Reversing History TRX], [Reversing Period ID], [Reversing TRX Source], [Reversing Year], Segment1, Segment2, Segment3, [Sequence Number], [Source Document],
[TRX Source], [Tax Date], Time, [Transaction Type], [Typical Balance], [User Defined 1], [User Defined 2], [User Who Posted], Voided, Segments,
[Workflow Approval Status], [Workflow Priority], [Ledger Name], [Ledger Description], [Account Index For Drillback], [Journal Entry For Drillback]
FROM dbo.AccountTransactions
WHERE ([Account Number] = '1000-000-00')
CASE
WHEN(MONTH(T1.[TRX Date]) = 1) THEN "January " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 2) THEN "February " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 3) THEN "March " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 4) THEN "April " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 5) THEN "May " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 6) THEN "June " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 7) THEN "July " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 8) THEN "August " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 9) THEN "September " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 10) THEN "October " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 11) THEN "November " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
WHEN(MONTH(T1.[TRX Date]) = 12) THEN "December " + CONVERT(VARCHAR(4), YEAR(T1.[TRX Date]))
END as 'Trx Month'
GO
どのようなステップがありますか?私は頭を悩ましており、どのように進行するか分からない。
'where'節で' case'式をタックしましたが、接続されていません。最初の用語( '([Account Number] = '1000-000-00')')に結びつけるものは何もありません。 'と'であり、 'case'式の値を使用するものは何もありません。 '... and case ... end = '2017年3月。 [This](https://stackoverflow.com/questions/10256848/can-i-use-case-statement-in-a-join-condition/10260297#10260297)答えはそれを明確にするのに役立ちます。 'from'節の前に、' case'を列リストに追加しようとしているようです。 – HABO