Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Use Table DataType variable into Dynamic SQL query

Author  Topic 

ranjeetsingh_6
Posting Yak Master

125 Posts

Posted - 2007-03-17 : 06:32:37
Hi
I have two problem in my store procedure
1:-Get result of Dynamic sql query into a variable.
2:How to use Table Datatype variable into Dynamic SQL query.
i have pointed my problem with red color

-----------------------------------------------------------------
alter procedure USP_GetRecordsAtTimeFrame
@Fromime varchar(40),@Jrid varchar(30),@timeframe integer,@UIDTABLE varchar(30)
as
declare @fromTime varchar(100),@TableRow int,@count integer,@SQLQuery1 varchar(100),@sqlquery2 varchar(1000),@c int
declare @TempUserID Table(timerecorded datetime,state varchar(250),Speed float,Place varchar(250))
set @fromTime=@Fromime
select @SQLQuery1='select @c=count(*) from'+' '+@UIDTABLE
exec sp_executesql @query=@SQLQuery1, @statement=N'@c int output',
@c=@TableRow output
while @count <=@TableRow
begin
select @sqlquery2='insert into '+' '+ @TempUserID +' '+'select top 1 timerecorded,state,Speed,Place from '+' '+
@UIDTABLE+' '+' where jrid='''+@Jrid+''' and convert(datetime,Timerecorded,103) >=convert(datetime,'''+@fromTime+''',103)'
exec(@sqlquery2)
set @count=@count+1
set @fromTime=DATEADD(mi, @timeframe, convert(datetime,@fromTime,103))
end
select * from @TempUserID


Ranjeet Kumar Singh

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-17 : 06:39:23
1. use sp_executesql see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80746
2. You can't. use Temp Table instead http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80747



KH

Go to Top of Page
   

- Advertisement -