Reputation: 2328
I am trying to print a tab in sql server using:
select 'tab-->' + char(9) + '<--tab'
But it doesn't seem to work and always prints
tab--> <--tab
Is there any thing I am missing?
Upvotes: 7
Views: 21052
Reputation: 1627
Upvotes: 1
Reputation: 1
Each Char(9)
or char(160)
is converted to a space.
If you align char(9)+char(9)+char(9) => you still got only 1 space.
So I tried these :
<"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)
Visually, I got what I wanted...
Upvotes: 0
Reputation: 32707
The thing about tabs is that they aren't a constant width. A tab character says "bring me to the next tab stop". If you currently have tab stops set at eight characters and the tab is at character six, the tab will only be one wide. But let's say you're skeptical (a good thing!). There's more evidence that the tab is actually being output. If you do something like print '>' + char(9) + '<'
, you'll notice that you can't select only one space in the gap, indicating that the whitespace that you're seeing is atomic. But more convincing to me is to paste it into an editor that allows you to see tabs. I use vim, but use whatever you like. In all cases I tested, the tab character showed up.
Upvotes: 0
Reputation: 37388
If you're testing this inside of Management Studio, the Results to Grid
(Ctrl + D) setting will change your tab to a space... try switching to Results to Text
(Ctrl + T) instead, and you will see the tab.
Alternately, you can change your select
to a print
:
print 'tab-->' + char(9) + '<--tab'
Outputs...
tab--> <--tab
Upvotes: 18