Current location - Recipe Complete Network - Complete cookbook - How to form an infinite menu with sql statements in sql server?
How to form an infinite menu with sql statements in sql server?
You mean sorting, right? I happen to have an example at hand. If you change it slightly, changing "."to'-' is the result you want.

Use? tempdb?

go to

What if? OBJECT_ID('TB ')? Is it? Isn't it? empty

Descending? Table? Tuberculosis (tuberculosis)

go to

Create? Table? Tuberculosis (tuberculosis)

(cBomList? NVARCHAR(200)? Isn't it? Empty)

go to

Insert? Become? Tuberculosis (tuberculosis)

Choice? ' 1'? Union? all

Choice? ' 1. 1'? Union? all

Choice? ' 1.2'? Union? all

Choice? ' 1. 1 1. 1 1'? Union? all

Choice? ' 1.2.2'? Union? all

Choice? '2. 1'? Union? all

Choice? '2. 1.3'? Union? all

Choice? '2.2'? Union? all

Choice? '3. 1'? Union? all

Choice? '3. 12'? Union? all

Choice? '3.2'?

go to

/* Convert the ranking to a fixed number of digits */

What if? OBJECT_ID('formatBom ')? Is it? Isn't it? empty

Descending? Function? Formatted Bom

Going?

Create? Function? 【dbo】。 [formatBom](@cBName? nvarchar( 100))

Return? varchar( 100)

be like

begin

Declare? @str? varchar( 100),@i? int,@tempV? nvarchar( 100),@ iBIndex? int? ,@iEIndex? int -? ,@bG? a little

Settings? @ I index = 1

Settings? @str= ' '

Settings? @i= 1

What if? len(@ CB name)& gt; 0

begin

Settings? @tempV=@cBName

What time? (@ i & lt=len(@tempV))

begin

What if? Substring (@tempV, @i, 1)=''

begin

Settings? @iEIndex=@i

Settings? @ str = @ str+right(cast(substring(@ tempV,@ I index,@ iEIndex-@ I index)? As? int)+ 100000,3)

Settings? @ iBIndex? =? @ me? +? 1

end

Settings? @i=@i+ 1

end

Settings? @ str = @ str+right(cast(substring(@ tempV,@ iBIndex,Len(@tempV)? +? 1? -? @iBIndex)? As? int)+ 100000,3)

end

Return (@str)

end

go to

Choice? *,dbo。 【format BOM】(cbom list)? From where? TB? Order? By who? dbo。 [Format List]