Jump to content

Changing the position of first name to the last name, and vise versa


radit91
 Share

Recommended Posts

SELECT SUBSTRING ( Name, CHARINDEX ( ' ', Name ) + 1, LEN ( Name ) ) + ', ' + SUBSTRING ( Name, 1, CHARINDEX ( ' ', Name ) ) as 'Name'

Hai guys. The code is about putting the last name to the front, the last name to the back, and put coma(,) in the middle. But, the code was to complicated for me. Can you please explaine it to me or maybe give other code that is much simpler and if you could with some explanation. I'm new to the SQL. Thankyou.

Edited by radit91
Link to comment
Share on other sites

Depending on which database you're using, check the reference for the string functions for that database to see what each of those functions (substring, charindex, len, etc) does. This is the string function reference for MySQL, for example: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...