how to rectify this error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmrhema
    Contributor
    • Jan 2007
    • 375

    how to rectify this error

    Hi,

    I want to retrieve the values from store_geofence table where the timeduration exceeds certain interval

    the procedure is as below[code=sql]
    CREATE
    procedure [dbo].[GeofenceByCusto mer]
    @regno nvarchar(50),
    @frmdate nvarchar(50),
    @todate nvarchar(50),
    @Geofence nvarchar(50),
    @interval int,
    @userid nvarchar(50)
    as
    begin
    declare @val int
    Declare @strSql as nvarchar(3000)
    Select @val=count(*) from basestation where superuserid=@us erid and
    base_station_na me=@Geofence

    --if(@val=0)
    begin
    create table #templ(registra tionno nvarchar(50),ba sestation
    nvarchar(50),en try_time datetime,exit_t ime datetime,durati on
    int)
    select @strSql='
    insert into #templ(registra tionno,basestat ion,entry_time, exit_time,durat ion)
    select
    registrationno, basestation,ent ry_time,exit_ti me,datediff(mi, entry_time,exit _time)
    as duration from store_geofence where entry_time>'+@f rmdate+' and
    exit_time<'+@to date+' and datediff(mi,ent ry_time,exit_ti me)>'+@interval +'
    and basestation in ('+@Geofence+') order by entry_time,regi strationno'
    execute (@strSql)
    print @strSql
    select * from #templ
    drop table #templ
    end

    end
    GO
    [/code]
    I should specify the duration in int to take affect

    datediff(mi,ent ry_time,exit_ti me)>'+@interval +'


    but i do not know how to rewrite this path
    i cannot put as
    datediff(mi,ent ry_time,exit_ti me)>'+@interval +'


    it returns an error
    Syntax error converting the nvarchar value '
    insert into #templ(registra tionno,basestat ion,entry_time, exit_time,durat ion)
    select
    registrationno, basestation,ent ry_time,exit_ti me,datediff(mi, entry_time,exit _time)
    as duration from store_geofence where entry_time>01/01/2008 and
    exit_time<01/01/2008 and datediff(mi,ent ry_time,exit_ti me)>' to a column of data type int.

    How should i rewrite it

    please help

    regards
    cmrhema
    Last edited by debasisdas; Apr 14 '08, 12:52 PM. Reason: added code=sql tags
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    I think the error is actually comming from the date comparison.
    There should be singe quotes around them
    like this

    insert into #templ(registra tionno,basestat ion,entry_time, exit_ time,duration)
    select
    registrationno, basestation,ent ry_time,exit_ti me,da tediff(mi,entry _time,exit_time )
    as duration from store_geofence where entry_time>'200 8-01-01' and
    exit_time<'2008-01-01' and datediff(mi,ent ry_time,exit_ti me)> etc

    As they are i think they are being read as 1 divided by 1 divided by 2008
    when the query sting is executed.



    Note, there won't be any entry_time that is both less than and greater than 2008-01-01

    Comment

    Working...