mst_AirPort表AirPortID (UNIQUEIDENTIFIER)AirPortCode
111111111111111111111         LAX
111111111111111111112         PVG
111111111111111111113         TPE
3111111111111111111113        SGN
3111111111111111111114        SAN就是根据'lax,pvg,tpe' 字符串,取mst_AirPort表的三个AirPortID ,再插入到AirPortGroup表中
INSERT INTO AirPortGroup(AirPortID,X)
VALUES ( AirPortID , x)
谢谢!

解决方案 »

  1.   

    INSERT INTO AirPortGroup(AirPortID,X) select AirPortID , AirPortCode as x from mst_AirPort where AirPortCode in 'lax,pvg,tpe' 
      

  2.   

    INSERT INTO AirPortGroup(AirPortID,X)
    select AirPortID , x from mst_airport where airportcode in('lax','pvg','tpe' )
      

  3.   

    good_______________________________回帖是种奉献!
    给分是种回报!
    欢迎光临:www.sodeer.com
    _______________________________
      

  4.   

    To,dawugui(潇洒老乌龟)
    不行的
    To,
    sdhylj(青锋--SS) 'lax,pvg,tpe' 这个字符串是动态得到的,我不能拆开加‘’啊,有其它的办法吗
      

  5.   

    试试这两个:
    INSERT INTO AirPortGroup(AirPortID,X)
    select AirPortID , x from mst_airport where airportcode in(replace('''lax,pvg,tpe''',',',''','''));

    INSERT INTO AirPortGroup(AirPortID,X)
    select AirPortID , x from mst_airport where airportcode in(replace('lax,pvg,tpe',',',''','''))
      

  6.   

    To:
    sdhylj(青锋--SS)不行啊,总不见得用游标吧。这样很损伤资源的。谢谢!
      

  7.   

    declare @s as varchar(100) --你的字符串
    set @s = 'lax,pvg,tpe'INSERT INTO AirPortGroup(AirPortID,X)
    select AirPortID , x from mst_airport where airportcode in(replace(@s, ',' , ''','''));
      

  8.   

    declare @val char(100),@sql char(800);
    set @val='lax,pvg,tpe';
    set @sql='INSERT INTO AirPortGroup(AirPortID,X) select AirPortID , x from mst_airport where  airportcode in('''+replace(@val,',',''',''')+''')';
    exec(@sql);
      

  9.   

    DECLARE @FGW AS NVARCHAR(100) 
    DECLARE @AirGrouplD UNIQUEIDENTIFIER
    SET @FGW = 'lax,pvg,tpe,sgn'
    SET  @FGW = ISNULL( @FGW,'')+ ','
    WHILE CHARINDEX(',',@FGW) >0
    BEGIN SELECT @AirGrouplD = AirPortID FROM MST_AirPort WHERE  AirPortCode =  LEFT (@FGW ,CHARINDEX(',',@FGW)-1)
    print convert(nvarchar(100),@AirGrouplD)  +''
    IF @AirGrouplD IS NOT NULL
    INSERT INTO AirPortGroup(AirPortGroupID, AirPortGroupName)
    VALUES (@AirGrouplD, @FGW)
    SET @FGW =STUFF (@FGW,1 , CHARINDEX(',',@FGW),'')
    END
      

  10.   

    在前台把字符串拆好,再用SQL进行查找、插入
      

  11.   

    To,
    sdhylj(青锋--SS)不行的。看似简单的方法,可能我门没有找到好的方法,不过谢谢大家了。