2012-09-16 112 views
-1

請幫忙,我一點都不擅長SQL,但我創建了下面的查詢。它從房間預訂系統提取信息以顯示在數字標牌產品上。姓氏,名字開關

目前'姓名'字段輸出爲lastname, firstname。我真的需要它顯示爲Firstname Lastname,但仍然在一列之下。

有人可以看看嗎?這將不勝感激。

SELECT 
    HOST9006.DESCRIPTION, 
    HOST0110.ROOMNAME, 
    HOST0140.NAME, 
    dateadd(mi, HOST0120.STARTMINS, HOST0120.MTGDATE) AS ASTART, 
    dateadd(mi, HOST0120.ENDMINS, HOST0120.MTGDATE) AS AFINISH, 
    CONVERT(VARCHAR(5), dateadd(mi, HOST0120.STARTMINS, HOST0120.MTGDATE) ,108) AS START, 
    CONVERT(VARCHAR(5), dateadd(mi, HOST0120.ENDMINS, HOST0120.MTGDATE) ,108) AS FINISH, 
    HOST0120.MTGKEY, HOST0120.HIPTYPE, HOST0120.ROOMKEY 
FROM 
    HOST0140 
    INNER JOIN HOST0120 
    ON HOST0120.OWNERKEY=HOST0140.PERSONKEY 
    INNER JOIN HOST9006 
    ON HOST9006.KEYVALUE=HOST0120.MTGSTATE 
    INNER JOIN HOST0110 
    ON HOST0110.ROOMKEY=HOST0120.ROOMKEY 
WHERE 
    CANCELSTATE='0' 
AND MTGDATE >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) 
AND MTGDATE < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1) 
AND MTGSTATE <> '11' 
ORDER BY START 

感謝

+1

給你的問題一個**有意義的標題 – abatishchev

+0

你正在使用哪種RDBMS? – fancyPants

回答

1

這應該讓你開始爲SQL服務器(你沒有指定你使用的是什麼RDBMS):

select substring(col1, charindex(',', replace(col1, ' ', '')) + 1, len(col1)) 
    + ' ' 
    + left(col1, charindex(',', col1) -1) as First_Last 
from names 

SQL Fiddle with Demo

0

這應該工作mySQL

select concat(right(Name, length(Name) - instr(Name, ',') - 1), ' ', left(Name, instr(Name,',')-1)) from mytable