2 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
我設(shè)法寫(xiě)了一些有用的東西,并根據(jù)您的輸入將空字符串和默認(rèn)值替換為超出范圍的數(shù)字。這是最終代碼:
DECLARE @defaultPersons int = 2;
@forDecisionTreeHouseTypeReplNulls =
SELECT [InstallationId],
[Persons],
(
(Func<string, int?>)
(inputString => // input_parameter
{
int _pers;
return ! int.TryParse([Persons], out _pers) || _pers <= 0 ?
@defaultPersons :
_pers > 10 ?
10 :
_pers;
}
)
) ([Persons]) AS [AdjPersons]

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
TryParse不是您可以直接調(diào)用的功能之一。它必須包裝為內(nèi)聯(lián)函數(shù)。一個(gè)簡(jiǎn)單的例子:
@output =
? ? SELECT FirstName,
? ? ? ? ? ? ? ?(
? ? ? ? ? ? ? ? (Func<string, int?>)
? ? ? ? ? ? ? ? (inputString =>? // input_paramater
? ? ? ? ? ? ? ? ? ? {?
? ? ? ? ? ? ? ? ? ? ? ? int outputValue;
? ? ? ? ? ? ? ? ? ? ? ? return int.TryParse(inputString, out outputValue) ? (int?)outputValue : (int?)null;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ?)
? ? ? ? ? ? ) (Salary) AS someDate
? ? FROM @Employees;
- 2 回答
- 0 關(guān)注
- 168 瀏覽
添加回答
舉報(bào)