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 8588537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:49:36+00:00 2026-06-11T22:49:36+00:00

I am using WebMatrix with SQL Server Compact, and just have a simple question.

  • 0

I am using WebMatrix with SQL Server Compact, and just have a simple question. I have a line of code:

if(cndDateLastModified=="gteq"){stringCompiler+="'CAST(DateLastModified AS datetime)' >= 'CAST(" + DateLastModified + " AS datetime)' ";}////

By plotting the output on the screen the query specifically looks like:

SELECT * FROM POITable WHERE 'CAST(DateLastModified AS datetime)' >= 'CAST(09/25/2012 AS datetime)'

For some reason, it returns all rows before, on, and after the date specified.
I’m still a little green when it comes to querying, but by all researched accounts, this should work. Clearly it is doing something I don’t quite expect, which is understandable, considering.

Any ideas on how I can get this to work the way I want it? Is it still trying to compare strings or some other format?

Note: I did try this with CONVERT(datetime, DateLastModified) and CONVERT(datetime, DateLastModified, 1) for both conversions.

Another Note: It is stored in the database as a string.

Another Note: If I switch the condition (from >= to <=) it does the opposite and returns no rows, which I would kind of expect considering the first unexpected result set, but still don’t know why.

Any ideas?

  • 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-11T22:49:37+00:00Added an answer on June 11, 2026 at 10:49 pm

    Because with the single quotes you are comparing two strings. ‘CAST(….)’ vs. ‘CAST(…)’. You may as well have written WHERE ‘Ginger’ >= ‘Fred’ you would get the same results. 😀

    What you should need is:
    FROM POITable WHERE CAST(DateLastModified AS datetime) >= CAST(’09/25/2012′ AS datetime)

    Use the single quotes around the literal date. ’09/25/2012′

    However if you’re using SQL server, you can just use WHERE CAST(DateLastModified AS datetime) >= ‘2012-09-25’

    Additionally, if the DateLastModified column of the table is already a date time, remove the cast. Cast is for converting strings to data types. My hunch is all you need is:

    WHERE DateLastModified >= '2012-09-25' /* ISO date strings are understood and accepted by SQL Server. */
    or
    WHERE DateLastModified >= GETDATE() /*Everything in the future, time inclusive.*/
    or
    WHERE DateLastModified >= DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) /* Everything starting today. */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server and WebMatrix Razor syntax to try and determine is
As my question states, I can't figure out why, but while using WebMatrix to
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
Using SQL Server 2008 R2 we are looking for a way to select the
I have developed a website using Asp.Net MVC which uses a SQL CE database
I have three .cshtml created using WebMatrix: MyClass.cshtml located at App_Code: @functions { public
Using SQL Server CE, I am trying to add a new column to the
I am using WebMatrix and have built a website based on the StarterSite. In
How can I publish my website in Webmatrix that uses a database, using Web
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question

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.