我认为目前有数百万条记录,我希望将其过滤为一个特定的帐号。我目前已决定使用帐号过滤器创建新的自定义视图(为了便于使用)。
我就是这样做的:
SELECT * FROM VIEW_NAME WHERE [帐号] =' 1000'
这完全符合我的预期。不过,我想创建一个名为VIEW_NAME_1000的全新视图,并进行另一项修改,我想根据已有的日期字段创建一个月份列。
我试过这个:
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'
我不知道我是否需要T1。参考,特别是因为我只是从我现有的视图中提取数据。
这是我的整个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
我错过了哪些步骤?我一直在绞尽脑汁,不知道如何继续。
答案 0 :(得分:3)
您可以将代码大幅简化为:
static navigationOptions = ({ navigation }) => {
return {
headerLeft: (
<Button transparent onPress={() => { navigation.goBack(); }}><Text>Back</Text></Button>
)
};
};
您不需要巨型CREATE VIEW [dbo].[VIEW_NAME_1000] AS
SELECT . . .,
DATENAME(MONTH, t.[TRX Date]) + ' ' + DATENAME(YEAR, t.[TRX Date])
FROM dbo.AccountTransactions t
WHERE [Account Number] = '1000-000-00';
表达式来生成月份名称。