请帮忙,我对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
由于
答案 0 :(得分:1)
这应该让你开始使用sql-server(你没有指定你正在使用的RDBMS):
select substring(col1, charindex(',', replace(col1, ' ', '')) + 1, len(col1))
+ ' '
+ left(col1, charindex(',', col1) -1) as First_Last
from names
答案 1 :(得分:0)
这适用于mySQL
select concat(right(Name, length(Name) - instr(Name, ',') - 1),
' ',
left(Name, instr(Name,',')-1))
from mytable