Solved

SQL varchar Date

Posted on 2011-09-06
1
265 Views
Last Modified: 2012-05-12
Hi Experts,

I just inheritted a badly setup database, where paymDate is varchar(20), but its contents is formatted as m/d/yyyy

My question is, in this case, how can I SELECT all records between 6/1/2011  and 6/30/2011?

When i do the following, i also get June 2010 data.

Thank you.
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 [id]
      ,[invoiceNumber]
      ,[paymentDate]
  FROM [citysightcarts].[dbo].[Invoices]
  
  WHERE [paymentDate] >= '7/1/2011'
    AND [paymentDate] <= '7/31/2011'
    
 ORDER BY id

Open in new window

0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 36491469
Please try:

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 [id]
      ,[invoiceNumber]
      ,[paymentDate]
  FROM [citysightcarts].[dbo].[Invoices]
  
  WHERE CONVERT(datetime, [paymentDate], 101) BETWEEN '7/1/2011' AND '7/31/2011'
    
 ORDER BY id

Open in new window


I hope this helps.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question