Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem with query

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2010-04-13 : 10:58:36
Declare @lngStoreId INT, @dtmReportStart datetime
Set @lngStoreId = 10988
Set @dtmReportStart = Cast('2010-02-01' as datetime)



Select dtmDateVehPurchased,*
From tblVehicle v
INNER JOIN tblCustomer c on c.lngCustomerId=v.lngCustomerId
WHERE lngStoreId = @lngStoreId
and dtmDateVehPurchased > @dtmReportStart

If I run this I get no results, if I change the where clause to this

nd dtmDateVehPurchased > Cast('2010-02-01' as datetime)

My results work, any ideas>

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-13 : 13:14:06
Looks like the second cast may be returning Jan 2 rather than Feb 1. What date values does it return, and what date values does the column contain? eg, are there any records > 1 Feb 2010, and does the query that returns some records return any of these?

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-14 : 00:04:03
do a
Select @dtmReportStart before select staement to see what value its returning

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -