html - TSQL select a string, repeated N times -


i looking way, inside tsql select statement, repeat string literal n times, n in integer select (or calculate) columns on table.

what doing, specifically, parsing hierarchical tree structure nested html unordered lists. so, suppose we're deep in tree, next entry shallow. need close bunch of open <ul> , <li> tags higher in tree. have done (but feel kludgy) is:

select case depth-next_depth     when -1 ''     when 0 ''     when 1 '</ul></li>'     when 2 '</ul></li></ul></li>'     when 3 '</ul></li></ul></li></ul></li>'     ...     end mytable 

i know create scalar function returnclosingtags(@n int) don't want add object database this. want happen in select statement don't have further modify db schema.

i know whole approach here (writing code myself parse tree html) may harebrained, feel free comment alternative... interested in question own sake, if "duh use .net library xyz this" i'd know if there's answer little sql puzzle.

sql server happens have function built-in: replicate().

select replicate('</ul></li>', depth) 

because returns same type first argument, might want cast() value varchar(8000) or varchar(max) first.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -