欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多项式展开系数

程序员文章站 2022-07-03 19:38:45
...
Declare @A int=7;
Declare @w nVarchar(3000)=''
Declare @s nVarchar(3000)=''
Declare @sql nvarchar(4000)=''

Select  
	@aaa@qq.com+',['+number+']',
	@aaa@qq.com+',isnull(['+number+'],'''') As ['+number+']'
	From
	(
		Select convert(Varchar(10),number) As number
		From master.dbo.spt_values
			Where type='P'  and number between 1 and 2*(@A+1)
	) S

Set @sql=
'
With T
As
(
	Select  number From master.dbo.spt_values
		Where type=''P'' And number between 1 and @A+1
)
Select '+Stuff(@s,1,1,'')+' From
(
	Select A.number*aaa@qq.com As A,B.number As B,
		Convert(Varchar(10),nullif(dbo.fn_c(A.number-1,b.number),0)) As C
		From  T A cross join T B
			Where b.number<aaa@qq.com
) s
Pivot
(
	max(c)
	for
	A in('+Stuff(@w,1,1,'') +')
)p'

exec sp_executesql @sql,N'@A int',@A



--排列
Create Function fn_p(@I int)
Returns int
As
Begin
	Declare @Rst int=1
	While @I>0
	Begin
		Set @aaa@qq.com*@I
		Set @aaa@qq.com
	End
	Return @Rst
end

--组合
Create Function fn_c(@n int,@m int)
Returns int
As
Begin
	 return dbo.fn_p(@m)/(dbo.fn_p(@n)*dbo.fn_p(@aaa@qq.com))
End

多项式展开系数