读取数据库时出错。“.”附近的语法不正确。 这是我的sql查询。有什么我应该改变的吗?
SELECT
Item.item_id AS 'ID',
Item.item_type AS 'Item Type',
Item.item_description AS 'Item Description',
Item.purchase_year AS 'Purchase Year',
Item.purchase_price AS 'Purchase Price',
Player.fname AS 'First Name',
Player.lname AS 'Last Name',
Player.sport AS 'Sport',
Player.position AS 'Position',
Player.team_f AS 'Current Team',
Item.inscription AS 'Inscription',
Item.dedication AS 'Dedication',
Item.condition AS 'Condition',
Item.value AS 'Estimate Value'
FROM Item
INNER JOIN Player
ON Item.player_id = Player.player_id
WHERE Item.item_type LIKE @SearchPam
OR Item.item_description LIKE @SearchPam
OR Player.fname LIKE @SearchPam
OR Player.lname LIKE @SearchPam
OR Player.sport LIKE @SearchPam
OR Player.position LIKE @SearchPam
OR Player.team_f LIKE @SearchPam
OR Player.team_s LIKE @SearchPam
OR Player.team_t LIKE @SearchPam
最佳答案
我会改变你的整个方法。您应该使用表别名,您需要标准化您的数据(team_f,team_s 表示您有重复的列),您需要格式化您的代码,使其清晰易读,而不是将数十行塞入一行。我担心你对每一个谓词都有喜欢。如果它有一个前导通配符,你的性能将会很糟糕。我要做的最后一个更改是使用存储过程而不是通过 sql,这样您就可以将数据与应用程序分开。
SELECT i.item_id AS ID
, i.item_type AS ItemType
, i.item_description AS ItemDescription
, i.purchase_year AS PurchaseYear
, i.purchase_price AS PurchasePrice
, p.fname AS FirstName
, p.lname AS LastName
, p.sport AS Sport
, p.position AS Position
, p.team_f AS CurrentTeam
, i.inscription AS Inscription
, i.dedication AS Dedication
, i.condition AS Condition
, i.value AS EstimateValue
FROM Item AS i
INNER JOIN Player AS p ON i.player_id = p.player_id
WHERE i.item_type LIKE @SearchPam
OR i.item_description LIKE @SearchPam
OR p.fname LIKE @SearchPam
OR p.lname LIKE @SearchPam
OR p.sport LIKE @SearchPam
OR p.position LIKE @SearchPam
OR p.team_f LIKE @SearchPam
OR p.team_s LIKE @SearchPam
OR p.team_t LIKE @SearchPam
关于asp.net - '.'附近的sql数据库语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33129621/