我想将记录插入一个表中,值为两个编号,第一个数据系统给出,第二个数据需要从另一张表中查询得到,怎么办呢?我是菜鸟啊!

解决方案 »

  1.   

    insert tab (col1,col2)
    select 数据系统给出的值 as col1,字段名 as col2
    from 另一张表
    where ...
      

  2.   

    declare @i int
    set @I = --系统值
    insert ta select @I,col from otherta
      

  3.   

    insert into 病人体检项目信息(编号,项目编号) " + this.id_label.Text + " as 编号,项目编号 as 项目编号 from 项目信息 where 项目名称=" + name这样写能行不?
      

  4.   

    insert into 病人体检项目信息(编号,项目编号) " + this.id_label.Text + " as 编号,项目编号 as 项目编号 from 项目信息 where 项目名称='" + name +"'"
    可能应该这样吧,注意数据类型
      

  5.   

    还是不行啊,一直显示 this.id_label.Text的值有语法错误
    比如我要插入数据为
    (1,2)
    (1,3)
    (1,4)
    他们在数据库中的数据类型都是nchar
      

  6.   


    'insert into 病人体检项目信息(编号,项目编号) valuse(' + this.id_label.Text + ' , select 项目信息 from 项目信息 where 项目名称='+ name +')'
      

  7.   

    insert into 病人体检项目信息(编号,项目编号) select " + this.id_label.Text + " as 编号,项目编号 as 项目编号 from 项目信息 where 项目名称='" + name +"'"