select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23执行上面语句,下面错误提示 sqlserver 数据库
消息 141,级别 15,状态 1,第 11 行
向变量赋值的 SELECT 语句不能与数据检索操作结合使用。
求解决方案 , 怎么赋值?

解决方案 »

  1.   

    不会吧:
    create table tablea(id int,ip varchar(15),apps varchar(10))
    insert into tablea select 23,'127.0.0.1','aaa'
    go
    declare @Variable1 varchar(15),@Variable2 varchar(10)
    select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23select @Variable1,@Variable2
    /*
    --------------- ----------
    127.0.0.1       aaa(1 行受影响)*/
    go
    drop table tablea
      

  2.   

    select @Variable1=ip,@Variable2 =apps from tablea where id = 23
      

  3.   

    select 后面除了@Variable1 = ip ,@Variable2 = apps外,是否还有其他的字段?
      

  4.   

    如果有多条记录,则获得最后一个:
    create table tablea(id int,ip varchar(15),apps varchar(10))
    insert into tablea select 23,'127.0.0.1','aaa'
    insert into tablea select 23,'127.0.0.2','abb'
    go
    declare @Variable1 varchar(15),@Variable2 varchar(10)
    select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23select @Variable1,@Variable2
    /*
    --------------- ----------
    127.0.0.2       abb(1 行受影响)*/
    go
    drop table tablea
      

  5.   

    你的select语句里要么赋值,要么查询,不能既查询又赋值。估计你的select里还有别的字段。
      

  6.   

    原始 句子 是这样 的select @countfile = count(1)  ,  
    @userup = sum(case uid when 0 then 0 else 1 end )  ,  
    @countsize  sum(filesize ) , 
    @countip count (distinct(uploadip))  ,
    @countdown = sum(downcount)  
    from up_fileinfo  where  CONVERT(char(8) , uploadtime, 112 )   =    @timechar
      

  7.   

    select top 1 @Variable1 = ip ,@Variable2 = apps from tablea where id = 23