Query Help
-
Please help. When I use @From it fails with the following error , but at the same time when I spesify date is runs fine. "The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value." Declare @From as varchar(10) Set @From =(case When DatePart (dw , getdate())=2 Then convert(varchar(10),(getDate()-3),101) When DatePart (dw , getdate())=4 Then convert(varchar(10),(getDate()-2),101) When DatePart (dw , getdate())=6 Then convert(varchar(10),(getDate()-2),101) Else convert(varchar(10),(getdate()),101) End ) select @From select dateentered from NormalizedData_Out n join MaxDate_Out m on n.StudentID= m.StudentID and (isnull(n.DateEntered, '1/1/1900') =isnull(m.maxdate, '1/1/1900')) and n.dateentered between @From and getdate() --and n.dateentered between '08/27/2003' and getdate()
-
Please help. When I use @From it fails with the following error , but at the same time when I spesify date is runs fine. "The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value." Declare @From as varchar(10) Set @From =(case When DatePart (dw , getdate())=2 Then convert(varchar(10),(getDate()-3),101) When DatePart (dw , getdate())=4 Then convert(varchar(10),(getDate()-2),101) When DatePart (dw , getdate())=6 Then convert(varchar(10),(getDate()-2),101) Else convert(varchar(10),(getdate()),101) End ) select @From select dateentered from NormalizedData_Out n join MaxDate_Out m on n.StudentID= m.StudentID and (isnull(n.DateEntered, '1/1/1900') =isnull(m.maxdate, '1/1/1900')) and n.dateentered between @From and getdate() --and n.dateentered between '08/27/2003' and getdate()
Either declare @From as datatype smalldatetime, not varchar or use Convert(smalldatetime,@From,101) in the where clause. onwards and upwards...