我正在使用SQL Server 2012,並且我有一個存儲過程。我收到上述錯誤的最後一部分是這部分:SQL存儲過程將數據類型varchar轉換爲bigint時出錯
Set @SQL = '
Select Style=case when AttNr = 2 then '''' else Entity end'[email protected]+'
From #Temp
Where Entity not in (Select Entity From #Temp Where AttNr=2 Group By Entity Having Sum(cast(Value as bigint))=0)
Group By Entity,AttNr
Order By Entity,AttNr
'
我在哪裏出錯了?
更新爲:
Set @SQL = '
Select Style=case when AttNr = 2 then '''' else Entity end'[email protected]+'
From #Temp
Where Entity not in (Select cast(Entity as varchar(100)) From #Temp Where AttNr=2 Group By Entity Having Sum(cast(Value as bigint))=0)
Group By Entity,AttNr
Order By Entity,AttNr
'
我必須做一些愚蠢的事 - 改爲:
Set @SQL = '
Select Style=case when AttNr = ''2'' then '''' else Entity end'[email protected]+'
From #Temp
Where Entity not in (Select cast(Entity as varchar(100)) From #Temp Where AttNr=2 Group By Entity Having Sum(cast(Value as bigint))=0)
Group By Entity,AttNr
Order By Entity,AttNr
'
好吧,我換到了下面:
Set @SQL = '
Select Style=case when AttNr = ''2'' then '''' else cast(Entity as varchar(100)) end'[email protected]+'
From #Temp
Where Entity not in (Select cast(Entity as varchar(100)) From #Temp Where AttNr=''2'' Group By Entity Having Sum(cast(Value as bigint))=0)
Group By Entity,AttNr
Order By Entity,AttNr
'
但仍然是一個沒有去 - 同樣的錯誤。
感謝,
邁克爾
你有沒有不會轉換的數據(即不是數字)? – JohnHC
將數字數據存儲在varchar列中時。 – jarlh
將其他實體部分轉換爲varchar – TheGameiswar