-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

谢谢

4

2 回答 2

1

这应该让您开始使用 sql-server(您没有指定您正在使用的 RDBMS):

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

请参阅带有演示的 SQL Fiddle

于 2012-09-16T14:23:40.020 回答
0

这应该适用于 mySQL

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

于 2015-07-13T18:26:53.297 回答