2011-11-02 97 views
0

我想這MSSQL查詢轉換爲MYSQLSQL Server查詢到MySQL查詢

查詢看起來像這樣

select tu.FirstName+' '+tu.LastName as name,tg.Name as game_name,tg.Status,tg.UserId,tg.gameid from tblUsers tu  
inner join tblGame tg on 
tu.UserId=tg.UserId where tg.Name LIKE @Name + '%' 

相同的查詢犯規返回任何記錄,當我在MYSQL運行它,什麼是問題 ?它的工作原理SQL服務器

回答

1
SELECT CONCAT_WS(' ', tu.FirstName, tu.LastName) AS name, tg.Name AS game_name,tg.Status,tg.UserId,tg.gameid 
FROM tblUsers tu  
INNER JOIN tblGame tg ON tu.UserId=tg.UserId 
WHERE tg.Name LIKE CONCAT(tu.FirstName, ' ', tu.LastName, '%') 

注意良好:

  • 它是區分大小寫的,我用大寫只是爲了可讀性
  • 我故意使用兩個CONCAT和CONCAT_WS向他們展示作爲選項
+0

謝謝你的工作 – user580950

0
select tu.FirstName+' '+tu.LastName as name,tg.Name as 
game_name,tg.Status,tg.UserId,tg.gameid from tblUsers tu 
inner join tblGame tg on 
tu.UserId=tg.UserId where tg.Name LIKE @Name + '%' 

select concat(tu.firstName,' ',tu.lastName) as name, ,tg.Name as 
game_name,tg.Status,tg.UserId,tg.gameid from tblUsers as tu 
inner join tblGame as tg on 
tu.UserId=tg.UserId where tg.Name LIKE concat(@Name,'%'); 

需要注意的是,不存在(例如)field1+' '+field2, 有concat,concat_wsgroup_concat, 閱讀它,它是非常有用的。