select * from           tableName     where id = "1";
像这样一句select语句,如何才能截取到"tableName"呢?

解决方案 »

  1.   

    declare @aa nvarchar(4000)
    set @aa='select * from           tableName     where id = "1";'
    select replace(substring(@aa,CHARINDEX(' from ',@aa)+6,CHARINDEX(' where ',@aa)-CHARINDEX(' from ',@aa)-6),' ','')
    --result
    tableName
      

  2.   

    the similiar answers is like HTTP://www.ebigear.com/Fund/PlayNews.php?NewsID=29966&ID=285885
      

  3.   

    declare @aa nvarchar(4000)---借用
    set @aa='select * from           tableName     where id = "1";'
    select @aa=ltrim(stuff(@aa,1,charindex('from',@aa)+3,''))
    select left(@aa,charindex(' ',@aa)-1)
    合并成一句(只考虑from,没有where也行)
    select left(ltrim(stuff(@aa,1,charindex('from',@aa)+3,'')),charindex(' ',ltrim(stuff(@aa,1,charindex('from',@aa)+3,'')))-1)
      

  4.   

    貌似问错地方了,我想要的是java语句