Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help retrieving single char from a string

Author  Topic 

donchamp
Starting Member

9 Posts

Posted - 2010-07-03 : 14:47:58
I have a column where i need to select the last character in a string from each row and place it in another column .Kindly guide me on how to achieve this

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-07-03 : 16:27:56
Lookup the RIGHT function in books online.
Go to Top of Page

donchamp
Starting Member

9 Posts

Posted - 2010-07-03 : 17:08:21
This is a variable length character string and I need to set a numeric value to another column based on the position of the last character. Kindly give any help on this.
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-07-03 : 20:37:02
So, do you need to select the last character - or do you need it identify the position of the last character?

Did you even bother reading up on the subject? If you want the last character from a variable length character string, you can use the RIGHT function, as in:

;With myData (col1, col2)
As (
Select 'abc', 'defghij'
Union All
Select 'abcde', 'zyesls'
)
Select *
,right(col1, 1)
,right(col2, 1)
From myData;

If you need the position of the last character, then you would use the DATALENGTH function, as in:

;With myData (col1, col2)
As (
Select 'abc', 'defghij'
Union All
Select 'abcde', 'zyesls'
)
Select *
,datalength(col1)
,datalength(col2)
From myData;

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-04 : 02:59:29
Hi donchamp,

Please avoid duplicate posting.
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=146840

Regards,
Bohra
Go to Top of Page
   

- Advertisement -