sql 游戏~四数,+-*/~得另一数---小结(原创)
CREATE FUNCTION f_ww(@var varchar(50),@vs varchar(50))
RETURNS char(1)
AS
begin
if len(@var) <> len(@vs)
RETURN 'F '
declare @str varchar(50),@char varchar(10)
declare @varcharint int,@vscharint int
declare @varstr varchar(50),@vsstr varchar(50)
set @str=@var+ ', '
while charindex( ', ',@str)> 0
begin
select @char=substring(@str,0,charindex( ', ',@str)),
@str=substring(@str,charindex( ', ',@str)+1,len(@str)-charindex( ', ',@str)),
@varcharint=0,@vscharint=0,
@varstr= ', '+@var+ ', ', @vsstr= ', '+@vs+ ', '
while(charindex( ', '+@char+ ', ',@varstr))> 0
begin
select @varcharint=@varcharint+1,
@varstr=substring(@varstr,charindex( ', '+@char+ ', ',@varstr)+1+len(@char),len(@varstr))
end
while(charindex( ', '+@char+ ', ',@vsstr))> 0
begin
select @vscharint=@vscharint+1,
@vsstr=substring(@vsstr,charindex( ', '+@char+ ', ',@vsstr)+1+len(@char),len(@vsstr))
end
if(@varcharint <> @vscharint)
RETURN 'F '
end
RETURN 'T '
end
go
create proc p_ww
@int1 dec(18,4),
@int2 dec(18,4),
@int3 dec(18,4),
@int4 dec(18,4),
@result dec(18,4)
as
begin
set nocount on
select DISTINCT a.id [aid],b.id [bid],c.id [cid],d.id [did] into #wei
from (select @int1 [id]
union all select @int2
union all select @int3
union all select @int4) a,(select @int1 [id]
union all select @int2
union all select @int3
union all select @int4) b,(select @int1 [id]
union all select @int2
union all select @int3
union all select @int4) c,(select @int1 [id]
union all select @int2
union all select @int3
union all select @int4) d
where dbo.f_ww(rtrim(a.id)+ ', '+ rtrim(b.id)+ ', '+ rtrim(c.id)+ ', '+ rtrim(d.id),rtrim(@int1)+ ', '+rtrim(@int2)+ ', '+rtrim(@int3)+ ', '+rtrim(@int4))= 'T '
create table #show(mula varchar(100),result int)
declare @count1 varchar(10),@count2 varchar(10),@count3 varchar(10)
declare @operator1 varchar(2),@operator2 varchar(2),@operator3 varchar(2)
set @count1= '+,-,*,/, '
while(chari