試圖運行查詢SQL查詢從另一臺SQL Server 2012的
select * from customers, TablesList where TablesList.TableName+'ID' =
10 and tableslist.tableid= 123
,其中來自其它表的列名獲得。我收到以下錯誤
Msg 245, Level 16, State 1, Line 1 Conversion failed when converting
the nvarchar value 'CustomersID' to data type int.
我知道我可以這樣做Select * from customers where customersID = 10
但是,試圖從另一個表中動態創建CustomersID
列名。這樣做的目的是有TablesList.TableName+'ID'
給我CustomersID
字符串,我可以使用等同於10
你確定這是整個查詢?我的意思是,除了您執行笛卡爾產品的事實之外,我沒有在您的查詢中的任何位置看到CustomersID'列 – Lamak
它具有TablesList.TableName +'ID'的意圖給了我可以用來等同的CustomersID字符串到10 –