-2

I have table in SQL Server 2008 called ,timestamplog which contains one column of name LogTime of typeINTEGER`

The values are like this:

1350468610,
1350468000,
1350381600,
1350295810

I need the values in between 1350468609 and 1350468001..

Please tell me how to query for those values.

I have try the following queries

select LogTime 
from timestamplog 
where LogTime between 1350468609 and 1350468001

select LogTime 
from timestamplog 
where LogTime >= '1350468610' and  LogTime <= '1350468000'

select LogTime 
from timestamplog 
where LogTime >= convert(decimal, 1350468610) and LogTime <= convert(decimal,1350468000)

select LogTime 
from timestamplog 
where LogTime >= convert(varchar, 12) and LogTime <= convert(varchar, 14)

But rows are not coming...

Actually the values in the table are the timestamps values stored as INTEGER in the table TIMELOG

IMP NOTE: Suppose if the values like 12,13,14 into table ,the above queries are working fine. But when I am comparing number of length 10 the query doesn't retrieve any values

Thanks in ADVANCE

user1716577
  • 29
  • 1
  • 7

1 Answers1

2

Because 1350468001 is less than 1350468609, if you reverse the order, any of your queries would work. I'd go with...

select LogTime from timestamplog where LogTime between 1350468001 and 1350468609

which is an inclusive range.

podiluska
  • 50,950
  • 7
  • 98
  • 104
  • +1 of course! :-) The query is right - but the `BETWEEN` values are flipped around :-) Good catch! – marc_s Oct 17 '12 at 07:35
  • The above query is not working – user1716577 Oct 17 '12 at 07:36
  • 1
    Then you probably have no values in that range. Have you got the numbers right? – podiluska Oct 17 '12 at 07:37
  • @podiluska The above query is not working – user1716577 Oct 17 '12 at 07:38
  • 2
    @user1716577 "is not working" doesn't help anyone help you. Does it produce an error? (If so, what error?). Does it produce the wrong results (If so, wrong how? Too many, too few, why should/shouldn't certain results be included?) Causes your machine to explode? (Not sure we can help with that one) – Damien_The_Unbeliever Oct 17 '12 at 07:38
  • @podiluska when i have values 12,13,14 my quries are working fine – user1716577 Oct 17 '12 at 07:39
  • @user1716577: do you get any results for `select LogTime from timestamplog where LogTime >= 1350468609` or `select LogTime from timestamplog where LogTime >= 1350468001` ? If not: then you just don't have those values in your table! – marc_s Oct 17 '12 at 07:39
  • @marc_s when i use select LogTime from timestamplog where LogTime >= 1350468001 or select LogTime from timestamplog where LogTime >= 1350468609 iam getting the resul – user1716577 Oct 17 '12 at 07:47
  • and if you do `select logtime from timestamplog where logtime>=1350468001 and logtime<=135048609` ? – podiluska Oct 17 '12 at 07:48
  • @ podiluska i tried the above query also, no row are retrived – user1716577 Oct 17 '12 at 07:49
  • @podiluska - there's a typo in your latest query - you're missing a `6`, so the second value is less than the first, as in the OPs question. – Damien_The_Unbeliever Oct 17 '12 at 07:50
  • @user1716577 Oops. How about `select logtime from timestamplog where logtime>=1350468001 and logtime<=1350468609 ` – podiluska Oct 17 '12 at 07:51
  • 1
    Then there is no data. Can you find a number that you think should be shown? – podiluska Oct 17 '12 at 08:03