我有這個疑問錯誤:字符串「聲明@ RepInt =」翻一番轉換無效
Dim count as integer = 4
Dim sql As String = " DECLARE @rep INT = " + count + "; " + _
" WITH cte AS " + _
" (" + _
" SELECT TOP (@rep) " + _
" ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS N " + _
" FROM sys.All_Columns ac1 " + _
" CROSS JOIN sys.ALL_Columns ac2 " + _
") " + _
" SELECT t.Barcode" + _
" FROM A_Documents t " + _
" CROSS JOIN cte " + _
" where idDocument = 'doc-123456' " + _
" ORDER BY t.Barcode desc; "
如果我把一個數字,沒有一個變種,IST的工作原理:
Dim sql As String = " DECLARE @rep INT = 4; " + _
但是,當我把我的COUNT變種,是不行的:
Dim sql As String = " DECLARE @rep INT = " + count + "; " + _
並出現此錯誤消息:
The conversion of string " Declare @RepInt=" to double is not valid
其實你並不需要聲明變量。你可以在TOP(+ count +)內立即傳遞它。其次考慮使用參數綁定而不是字符串連接。另外如果你需要將'count'轉換爲字符串。 – lad2025
再次感謝您的幫助,我不能回答您的評論,因爲不是答案 –
不要緊,請在下面提出答案;) – lad2025