아래 sql문을 실행 하면  위의 에러가 나타납니다
그래서 아래 처럼 DECLARE @AATVP  tickstockTYPE을 @sql1 문에 포함 시키면 아에 
SELECT top 1 되는게 없이 null로 나타납니다
헌데 sql문을 그대로 실행하면 또 잘 실행되서 top1 에 테이블 데이타가 나타남  
이유를 모르겠읍니다
sql문없이 돌린 소스
DECLARE @AATVP  tickstockTYPE


INSERT INTO  @AATVP

SELECT top 1
time  ,
yymmdd  ,
PowerMD  ,
HighPowerMD ,
HighPowerMDTime  ,
LowPowerMD ,
LowPowerMDTime   ,
HighPriceD  ,
HighPriceDTime  ,
LowPriceD  ,
LowpriceDTime
,TRMDYear
,2  as
inserttype
from  santa62.dbo.tickstock a  --and time <= @p1stTimeCharttmp
join 
(select  top 1 shcode, TRMDYear  from  tickchart  where shcode = '134780' ) b  
on a.shcode  =  b.shcode
where a.shcode = '134780' and a.yymmdd >= 160926  order by yymmdd asc, time asc 


원 소스 
DECLARE @AATVP AS tickstockTYPE
declare @shcode char(6)

CREATE TYPE tickstockTYPE AS TABLE
(
time  datetime,
yymmdd  char(6),
PowerMD  bigint,
HighPowerMD int,
HighPowerMDTime  datetime,
LowPowerMD int,
LowPowerMDTime  datetime ,
HighPriceD  int,
HighPriceDTime  datetime,
LowPriceD  int,                 --10
LowpriceDTime  datetime
,TRMDYear  int
,inserttype int  --1 tickstock으로 insert  2.tickchart로 insert
);
go 

set @sql1 =N'

DECLARE @AATVP  tickstockTYPE


INSERT INTO   @AATVP)

SELECT top 1
time  ,
yymmdd  ,
PowerMD  ,
HighPowerMD ,
HighPowerMDTime  ,
LowPowerMD ,
LowPowerMDTime   ,
HighPriceD  ,
HighPriceDTime  ,
LowPriceD  ,
LowpriceDTime
,TRMDYear
,2  as
inserttype
from  santa' +convert(varchar,@dbnum)
set @sql2= N'.dbo.tickstock a  --and time <= @p1stTimeCharttmp
join 
(select  top 1 shcode, TRMDYear  from  tickchart  where shcode = '''+convert(varchar,@shcode)+''' ) b  
on a.shcode  =  b.shcode
where a.shcode = '''+convert(varchar,@shcode)+''' and a.yymmdd >= '+convert(varchar,@firstdate)+'  order by yymmdd asc, time asc ' 

set @sql2 = @sql1+@sql2 
EXEC sp_executesql @sql2
PRINT @sql2