当前位置: 代码迷 >> Sql Server >> sql 游戏~四数,+-/~得另一数-小结(原创)解决方案
  详细解决方案

sql 游戏~四数,+-/~得另一数-小结(原创)解决方案

热度:522   发布时间:2016-04-27 18:22:42.0
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   @[email protected]+ ', '
  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= ', '[email protected]+ ', ',   @vsstr= ', '[email protected]+ ', '
    while(charindex( ', '[email protected]+ ', ',@varstr))> 0
    begin
      select   @[email protected]+1,
        @varstr=substring(@varstr,charindex( ', '[email protected]+ ', ',@varstr)+1+len(@char),len(@varstr))
    end
   
    while(charindex( ', '[email protected]+ ', ',@vsstr))> 0
    begin
      select   @[email protected]+1,
        @vsstr=substring(@vsstr,charindex( ', '[email protected]+ ', ',@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(charindex( ', ',@count1)> 0)
begin
select   @operator1=substring(@count1,0,charindex( ', ',@count1)),
  相关解决方案