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 2000 Forums
 Transact-SQL (2000)
 SPACE and REPLICATE help needed

Author  Topic 

rgiannone
Starting Member

3 Posts

Posted - 2004-02-03 : 11:29:24
Hello,

I am building a bill of material where based on the level each part is in the bill of material I want to add a number of leading spaces to the output. I can't seem to be able to add the number of spaces as the output comes out without the leading spaces. The REPLICATE function works with the hypen but not the space. HELP!!!

SELECT REPLICATE("-",(levelNo-1)*5) + customer_number
FROM #tree, pd_parts_master
WHERE #tree.id = pd_parts_master.entry_id
ORDER BY part_sequence

The above code produces this:
A 251 620 01 87
-----A 251 620 01 86
----------A 251 610 01 76
----------A 251 610 02 76
----------A 251 610 04 10
-----A 251 625 01 86
-----A 251 626 40 16

Changing to SELECT REPLICATE(" ",(levelNo-1)*5) + customer_number produces this:
A 251 620 01 87
A 251 620 01 86
A 251 610 01 76
A 251 610 02 76
A 251 610 04 10
A 251 625 01 86
A 251 626 40 16

Changing to SELECT SPACE((levelNo-1)*5) + customer_number produces this:
A 251 620 01 87
A 251 620 01 86
A 251 610 01 76
A 251 610 02 76
A 251 610 04 10
A 251 625 01 86
A 251 626 40 16

Thank you very much for your assistance.

Robert Giannone




nr
SQLTeam MVY

12543 Posts

Posted - 2004-02-03 : 11:54:25
I suspect this is due to where you are displaying it.
It's the same code that I use here
http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Try changing the font to courier.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -