September 16th, 2012, 08:53 AM
Lastname, Firstname switch
Please help, im not at all good with SQL but I have created the query below. It pulls information from a room booking system to display on a digital signage product.
At present the 'Name' field outputs as lastname, firstname. I really need it to display as Firstname Lastname but still under the one column.
Can someone take a look please? It would be greatly appreciated.
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
INNER JOIN HOST0120
INNER JOIN HOST9006
INNER JOIN HOST0110
AND MTGDATE >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
AND MTGDATE < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)
AND MTGSTATE <> '11'
ORDER BY START
September 17th, 2012, 06:51 AM
If the column 'NAME' has the data stored in that fashion you need to apply logic to it via a procedure to split it and rearrange it.
have a look here : http://stackoverflow.com/questions/5...-column-values
That should help with getting the column outputted as you prefer.
September 17th, 2012, 08:21 AM
if anyone else wants to tackle this problem, make sure you read this thread first, so you're not duplicating your effort needlessly
September 17th, 2012, 11:48 AM
ah , I see you had already provided a charindex method!
September 17th, 2012, 12:29 PM
that wasn't me, and i'm guessing it wasn't the original poster either
thus illustrating the evil of cross-posting, imagine if you had sat down and tried to work out that solution yourself for the guy, and yet someone else already did
i hate cross-posts
September 18th, 2012, 03:32 AM
I understand your sentiment for cross-posting, but sometimes, I do it myself.
Especially when I am after input/advice regarding a situation rather than a specific solution to a problem.
The more input and advice from as many people as possible the better.
The other issue can be the timezone difference, I might be after a quick answer due to a serious problem, and cannot wait for USA to wake up!
However, If I cross post forums, I will always come back and tell the forum without an answer, that I have found one and what it was, even if it means linking to a competitors forum!