insert into trainstation(trainID,stationID,arriveTime,startTime,runTime,distance,hard_seat,soft_seat,hard_sleep,soft_sleep) values('1043',select stationID from station where stationName ='奎屯','11:08','终点站','37小时43分','2810','143','-','280/291/303','469/492')
这个要怎么改才对啊stationID这个字段数据是另外张表查的

解决方案 »

  1.   

    insert into trainstation(trainID,stationID,arriveTime,startTime,runTime,distance,hard_seat,soft_seat,hard_sleep,soft_sleep) values('1043',(select stationID from station where stationName ='奎屯'),'11:08','终点站','37小时43分','2810','143','-','280/291/303','469/492')
    加个括号就行了,但要保证返回结果是一条记录,其它的语法我没看
      

  2.   

    select stationID from station where stationName ='奎屯'
    这个SQL查出来的值可能不只一条,LZ这样写当然不对LZ试试分开写SQL把,先写select stationID from station where stationName ='奎屯'获取ID,如果ID只有一个,就把ID作为参数执行insert
      

  3.   

    insert into trainstation(trainID,stationID,arriveTime,startTime,runTime,distance,hard_seat,soft_seat,hard_sleep,soft_sleep) values('1043',(select top 1 stationID from station where stationName ='奎屯'),'11:08','终点站','37小时43分','2810','143','-','280/291/303','469/492')
      

  4.   

    这个问题大了。stationName ='奎屯' 有多条记录的
      

  5.   

    insert into trainstation(trainID,stationID,arriveTime,startTime,runTime,distance,hard_seat,soft_seat,hard_sleep,soft_sleep) values('1043',(select top 1 stationID from station where stationName ='奎屯'),'11:08','终点站','37小时43分','2810','143','-','280/291/303','469/492')
      

  6.   

    真对不起我没测试就说了,应该是这样
    insert into trainstation(trainID,stationID,arriveTime,startTime,runTime,distance,hard_seat,soft_seat,hard_sleep,soft_sleep) select stationID '1043','11:08',..... from station where stationName ='奎屯'