Solved

How to write a query using the field dtRequested which is defined as type varchar using SQL Server 2005?

Posted on 2013-05-23
1
256 Views
Last Modified: 2013-05-23
I am trying to run a query against a SQL Server 2005 table that has a field titled dtRequested defined as varchar(500) with values such as:

8/8/2005
May 24 2005 12:00AM

Do you know how I could write a query using a WHERE clause in which I can retrieve
records where dtRequested is > 12/31/2011. In other words, I want records with dates
for years 2012 and 2013 only.

I tried the following query but it doesn't pull in records with dtRequested values greater than '12/31/2011'.

My query is as follows:

SELECT dev AS Developer, userNameF + ' ' + userName AS 'User', appname AS 'Application Name', dtRequested AS 'Date Requested', changeRequest AS Request, reason AS Reason,
tSOXSignOFF.dtUsrSignOff
FROM tSOXUsrRequest LEFT OUTER JOIN tSOXSignOFF ON
tSOXUsrRequest.reqID = tSOXSignOFF.reqID
WHERE (tSOXSignOFF.usrSignOff='Yes') and devid='zimmermj'
and dtRequested > '12/31/2011'
0
Comment
Question by:zimmer9
1 Comment
 
LVL 25

Accepted Solution

by:
Ron M earned 500 total points
ID: 39191163
SELECT dev AS Developer, userNameF + ' ' + userName AS 'User', appname AS 'Application Name', dtRequested AS 'Date Requested', changeRequest AS Request, reason AS Reason,
tSOXSignOFF.dtUsrSignOff
FROM tSOXUsrRequest LEFT OUTER JOIN tSOXSignOFF ON
tSOXUsrRequest.reqID = tSOXSignOFF.reqID
WHERE (tSOXSignOFF.usrSignOff='Yes') and devid='zimmermj'
and CAST(dtRequested as DateTime) > '12/31/2011'
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now