Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Inserting TAB into string Expand / Collapse
Author
Message
Posted Tuesday, October 06, 2009 10:40 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 11:35 AM
Points: 31, Visits: 509
Hi all,
This is for SQL 2000. I am trying to add a tab character to a string using char(9) but all I get is a single space.
Example:
select 'there should be a tab between here' + char(9) + 'and here'

Ideas?
Thanks.
Post #798676
Posted Tuesday, October 06, 2009 10:56 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, April 04, 2014 9:22 PM
Points: 1,525, Visits: 4,070
What are you using to verify that you only get a space? You're not going to see it in QA or SSMS, as they don't show things like carriage returns/tabs/etc. If you select that cell into a front end that does display those things, it may work fine.

Seth Phelabaum
Consistency is only a virtue if you're not a screwup.

Links: How to Post Sample Data :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
Post #798680
Posted Tuesday, October 06, 2009 11:06 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 11:35 AM
Points: 31, Visits: 509
Ahh, I was only looking in QA then copy/paste to Notepad. The finished output does have the tab.
Thanks.
Post #798684
Posted Tuesday, October 06, 2009 9:26 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 19, 2012 10:25 PM
Points: 1,231, Visits: 3,483
RD-201664 (10/6/2009)
select 'there should be a tab between here' + char(9) + 'and here'
Ideas?

declare @result varchar(100)
set @result = 'TEST START'+char(9)+'EXEC'+char(9)+'TEST END'
select @result

RESULT
TEST START EXEC TEST END

set @result = replace(@result,char(9),' -TAB HERE- ')
select @result

RESULT
TEST START -TAB HERE- EXEC -TAB HERE- TEST END
Post #798905
Posted Wednesday, March 13, 2013 4:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:38 AM
Points: 1, Visits: 0
I add the same problem with SQL Server :
"something"+char(9)+"something"
returns something something
"something"+char(9) + char(9)+char(9)+char(9)+char(9)+char(9)+"something"
returns something something


finally, I "cheated" with :

"something"+char(9)+char(160)+char(9)+char(160)+char(9)+char(160)+char(9)+char(160)"something"
returns something [8 spaces here] something (each char9 or char16 is replaced by a space)

so visually I got what I wanted, even if I admit it is not very elegant...
Post #1430291
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse