用update .... select.....语句

解决方案 »

  1.   

    能说详细点吗  我这个就是update select 语句呀
      

  2.   

    Select ID from employee where job_title = 'Drapery CSR 1'-------------
    句话的返回结果多于一个,不能用于Set赋值语句.因为Set语句要求的是一个唯一的确定的值.
      

  3.   

    Update contact 
    set  CSR = (Select top 1 ID from employee where job_title = 'Drapery CSR 1')
      

  4.   

    我知道大家的意思,上面我也说了是查询许多结果,但是我想能不能转换一下 ,相当于循环语句
    每次CSR能得到SELECT的一个值  SQL能实现这个吗?
      

  5.   

    employee 和 contact 表中行数可能不同,而且CSR与ID之间又没有约束关系,所以Sql是不可能完成这样的功能的。
      

  6.   


    假设 contact 有ID为主键,并且contact 和employee 的主键均不为identity可以用下面的语句select identity(int,1,1) idindex,[ID] into #temp1  from contact 
    Select identity(int,1,1) idindex,[ID] into #temp2 from employee where job_title = 'Drapery CSR 1'update contact set 
    scr = t2.id
    from #temp1 t1 inner join #temp2 t2
    on t1.idindex = t2.idindex and t1.[id] = contact.[id]
      

  7.   

    按照楼上的方法 
    select identity(int,1,1) idindex,CSR into #temp1  from contact 
    Select identity(int,1,1) idindex,employee_id into #temp2 from employee where job_title = 'Drapery CSR 1'update contact set 
    CSR = t2.employee_id
    from #temp1 t1 inner join #temp2 t2
    on t1.idindex = t2.idindex and t1.CSR = contact.CSR出现错误
    The column prefix 'contact' does not match with a table name or alias name used in the query.
      

  8.   

    错误提示是contact不是表名或是alias 名。
    意思是,你是不是在指定的数据库下面?