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 2008 Forums
 Transact-SQL (2008)
 Help with string code

Author  Topic 

mystical
Starting Member

10 Posts

Posted - 2011-09-16 : 13:14:34
Part of my existing code reads as
(trim(nm.nme_ttl_cde) ||'. '||trim(nm.frs_nme_txt))|| ' ' ||nm.snm_txt as Customer,
which produes the result

Mr. James Smith

how can i adjust the code to produce the result

Mr. J. Smith

With thanks

Bob

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-16 : 13:21:55
use SUBSTR function

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mystical
Starting Member

10 Posts

Posted - 2011-09-16 : 14:03:24
Thank you, but i am new to this - how do i incorperate it into the existing code ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-16 : 14:07:42
(trim(nm.nme_ttl_cde) ||'. '||substr(trim(nm.frs_nme_txt)),1,1)|| '. ' ||nm.snm_txt as Customer,

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mystical
Starting Member

10 Posts

Posted - 2011-09-16 : 15:27:12
Sorry but it keep coming up as
"Syntax error expecting something between the ")" and ")"

I have kept trying to re adjust the ), but i still get the same answer.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-09-16 : 15:34:24
You're using Oracle, right?

This is a SQL Server Board



DECLARE @nme_ttl_cde varchar(10) = 'Mr'
DECLARE @frs_nme_txt varchar(10) = 'James'
DECLARE @snm_txt varchar(10) = 'Smith'


SELECT (RTRIM(@nme_ttl_cde) +'. '+RTRIM(@frs_nme_txt))+ ' '+@snm_txt AS Customer

SELECT (RTRIM(@nme_ttl_cde) +'. '+SUBSTRING(@frs_nme_txt,1,1))+ '. '+@snm_txt AS Customer



You can try here:

http://www.dbforums.com/oracle/

But you should be able to convert what I posted

SELECT TRIM(nme_ttl_cde)||'. '||SUBSTRING(frs_nme_txt,1,1)||'. '||snm_txt AS Customer


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

mystical
Starting Member

10 Posts

Posted - 2011-09-16 : 16:28:17
Thank you the second "trim" was not required and the i get the result i was after using your substring code.
Go to Top of Page
   

- Advertisement -