Issue with using CASE SQL statement as Field
Issue with using CASE SQL statement as Field

When using a case statement as a custom field in Editor, the debug seems to ignore the field name I attempt to give it in the query. This is with the .NET libraries.
The query generated is:
Query: "SELECT [Id] as 'Id', (CASE WHEN LoanPersonUserName IN (SELECT UserName FROM dbo.EmployeeTree('username'')) AND Requester_UserName <> 'username' AND 3 IN(6,7,12) THEN 1 ELSE 0 END) as '(CASE WHEN LoanPersonUserName IN (SELECT UserName FROM dbo.EmployeeTree('jbarnes')) AND Requester_UserName <> 'jbarnes' AND 3 IN(6,7,12) THEN 1 ELSE 0 END)', [Requested] as 'Requested', [Requester] as 'Requester', [Requester_UserName] as 'Requester_UserName', [Recipient] as 'Recipient', [Recipient_UserName] as 'Recipient_UserName', [Percentage] as 'Percentage', [Bps] as 'Bps', [LoanNumber] as 'LoanNumber', [StartDate] as 'StartDate', [EndDate] as 'EndDate', [SplitState] as 'SplitState', [LoanFundedDate] as 'LoanFundedDate', [LoanPersonUserName] as 'LoanPersonUserName', [UserCanApproveSplit] as 'UserCanApproveSplit' FROM [v_SplitView] "
I expect the query to have AS 'FieldName' but it repeats the CASE statement which causes the error to be "Incorrect Syntax near 'username'.
Removing the single quotes then causes the error to state that the identifier field is too long, since it using the case statement as the field name.
This is how I'm setting the field on the server side:
editor.Field(new Field(canApprove, "UserCanApproveSplit"));
The canApprove variable is created via a simple string concat for now that just plugs in the username where applicable in the CASE statement.
Am I doing something incorrectly with this?
This question has an accepted answers - jump to answer
Answers
Yes, for more complex SQL queries such as this you'd need to use a VIEW (example - its PHP there, but the .NET download has the matching example for .NET).
Allan