Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8464747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:50:46+00:00 2026-06-10T14:50:46+00:00

I have some data in a table and I want to query it for

  • 0

I have some data in a table and I want to query it for data from it and depending upon when the query is is executed I want the query to take the current time stamp into consideration.

For example

declare @data table (id int, value nvarchar (50))

insert into @data values (1, 'First value')
insert into @data values (2, 'Second value')
insert into @data values (3, 'Third value')
insert into @data values (4, 'Fourth value')

Query 1

select * from @data
where value != 'First value'
and (value != 'Second value' and  '2012-08-30 23:59:59' between '2012-08-30 23:59:59' and '2012-09-15 23:59:59')

Query 1 Returns ‘Third value’ and ‘Fourth value’

Query 2

select * from @data
where value != 'First value'
and (value != 'Second value' and  '2012-08-29 23:59:59' between '2012-08-30 23:59:59' and '2012-09-15 23:59:59')

Query 2 don’t return any values, I want it to return
‘Second value’
‘Third value’
‘Fourth value’

All help is appreciated
Regards,
Jesper

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:50:48+00:00Added an answer on June 10, 2026 at 2:50 pm

    Your second query will never return any values, as ‘2012-08-29 23:59:59’ is not between the other two dates.

    It will certainly never return ‘Second Value’, as you specifically exclude it.

    I think you need to be a bit clearer on the logic you are trying to implement, maybe replacing the last AND with an OR NOT will get you closer, but this is a guess.

    select * from @data
    where value != 'First value'
    and (value != 'Second value' OR NOT ( '2012-08-29 23:59:59' between '2012-08-30 23:59:59' and '2012-09-15 23:59:59'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given I have table with some data... I have a query which is used
Hey guys, I have an application that I want to display some data from
i have used below linq query to join some table to get accurate data..
I have some simple query: SELECT foo, bar FROM table i think you now
I want to move some data from one table to another. I wrote a
I have some data from two tables: Table prod_schedule Line Model Lot_no Quantity Lot_Quantity
In a nutshell: I have some database table data that I want to populate
I have some data in a table that looks roughly like the following: table
I have some data in an SQL table with an XML datatype column where
I have some data that I have to display as a table. I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.