我有這個查詢是基於@Amount
參數轉換失敗
Amount varchar(20)= NULL
SELECT .....
Format(T1.Amount, 'c', 'en-us') as Amount1,
Format(T2.Amount, 'c', 'en-us') as Amount2
FROM Table1
WHERE .....
AND (T1.Amount>= CAST(@Amount AS INT) OR T2.Amount >= CAST(@Amount AS INT))
AND @Amount IS NOT NULL
如果@Amount
參數不是NULL
和是數字查詢完美的工作,但如果@Amount
參數是'%'
或NULL
我得到上述轉換錯誤。
關於如何解決這個問題的任何想法?檢查
您正在使用哪種SQL Server版本? SQL Server 2012+支持[TRY_PARSE](https://msdn.microsoft.com/en-us/library/hh213126.aspx)函數可以幫助你。 –
爲什麼你認爲你可以將'%'值轉換爲int? – Tanner
您還可以使用IsNumeric函數並通過使用IsNumeric函數應用大小來設置值。 –