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.
| Author |
Topic |
|
ranjeetsingh_6
Posting Yak Master
125 Posts |
Posted - 2007-03-17 : 06:32:37
|
| HiI have two problem in my store procedure1:-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)asdeclare @fromTime varchar(100),@TableRow int,@count integer,@SQLQuery1 varchar(100),@sqlquery2 varchar(1000),@c intdeclare @TempUserID Table(timerecorded datetime,state varchar(250),Speed float,Place varchar(250))set @fromTime=@Fromimeselect @SQLQuery1='select @c=count(*) from'+' '+@UIDTABLEexec sp_executesql @query=@SQLQuery1, @statement=N'@c int output', @c=@TableRow outputwhile @count <=@TableRowbeginselect @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+1set @fromTime=DATEADD(mi, @timeframe, convert(datetime,@fromTime,103))endselect * from @TempUserIDRanjeet Kumar Singh |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|