2

Is there a way to add the "-" carector instead of speces in the below column in my select statement:

SPACE(([Depth]-1)*4) + [OrgUnitName] AS [OrgUnitName],

So right now it adds spaces for however many depths there are. Is it possible to have this add the "-" charector instead of the spaces? The data is locations so it could have spaces between the words as well.

So for:

Test
 Test2
  Test23

I want:

Test
-Test2
--Test23

1 Answer 1

3

From the documentation of REPLICATE:

REPLICATE ( string_expression ,integer_expression )

That is

REPLICATE ('-', ([Depth]-1)*4) + [OrgUnitName] AS [OrgUnitName],

in your case.

However I prefer to return Depth as an output column and format the dashes with code. As little formatting and logic as possible in the SQL queries increases maintainability in my experience.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.