| Author |
Topic |
|
cmrhema
Starting Member
20 Posts |
Posted - 2008-04-13 : 11:16:08
|
| Hi,I want to retrieve the values from store_geofence table where the timeduration exceeds certain intervalthe procedure is as belowCREATE procedure [dbo].[GeofenceByCustomer]@regno nvarchar(50),@frmdate nvarchar(50),@todate nvarchar(50),@Geofence nvarchar(50),@interval int,@userid nvarchar(50)asbegindeclare @val intDeclare @strSql as nvarchar(3000)Select @val=count(*) from basestation where superuserid=@userid andbase_station_name=@Geofence--if(@val=0)begin create table #templ(registrationno nvarchar(50),basestationnvarchar(50),entry_time datetime,exit_time datetime,durationint) select @strSql=' insert into #templ(registrationno,basestation,entry_time,exit_time,duration) selectregistrationno,basestation,entry_time,exit_time,datediff(mi,entry_time,exit_time)as duration from store_geofence where entry_time>'+@frmdate+' andexit_time<'+@todate+' and datediff(mi,entry_time,exit_time)>'+@interval+'and basestation in ('+@Geofence+') order by entry_time,registrationno' execute (@strSql) print @strSql select * from #templ drop table #templendendGOI should specify the duration in int to take affectdatediff(mi,entry_time,exit_time)>'+@interval+'but i do not know how to rewrite this pathi cannot put asdatediff(mi,entry_time,exit_time)>'+@interval+'it returns an errorSyntax error converting the nvarchar value ' insert into #templ(registrationno,basestation,entry_time,exit_time,duration) selectregistrationno,basestation,entry_time,exit_time,datediff(mi,entry_time,exit_time)as duration from store_geofence where entry_time>01/01/2008 andexit_time<01/01/2008 and datediff(mi,entry_time,exit_time)>' to a column of data type int.How should i rewrite itplease helpregardscmrhema |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-13 : 11:20:29
|
| datediff(mi,entry_time,exit_time)>'+convert(varchar(20),@interval)+'==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-13 : 11:31:16
|
i dont think you really need to use dynamic sql here. Can you try removing the dynamic sql like this & try:-CREATEprocedure [dbo].[GeofenceByCustomer]@regno nvarchar(50),@frmdate nvarchar(50),@todate nvarchar(50),@Geofence nvarchar(50),@interval int,@userid nvarchar(50)asbegindeclare @val intDeclare @strSql as nvarchar(3000)Select @val=count(*) from basestation where superuserid=@userid andbase_station_name=@Geofence--if(@val=0)begincreate table #templ(registrationno nvarchar(50),basestationnvarchar(50),entry_time datetime,exit_time datetime,durationint)insert into #templ(registrationno,basestation,entry_time,exit_time,duration)selectregistrationno,basestation,entry_time,exit_time,datediff(mi,entry_time,exit_time)as duration from store_geofence where entry_time>@frmdateand exit_time<@todate and datediff(mi,entry_time,exit_time)>@intervaland ','+ @Geofence + ',' like '%,' + basestation + ',%'order by entry_time,registrationnoselect * from #templdrop table #templend endGO |
 |
|
|
|
|
|