Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select top 100 percent *  from RawData  where SiteId=@SitePId and convert(datetime, date, 103) between @StartDate and @EndDate  order by convert(datetime, date, 103)


when i run above query i am getting below error

Error converting data type varchar to datetime.

here date column is varchar type
@startDate is Datetime
@Enddate is Datetime

i have to sort date column between startdate and enddate

What I have tried:

C#
<pre lang="SQL">select top 100 percent *  from RawData  where SiteId=@SitePId and convert(datetime, date, 103) between @StartDate and @EndDate  order by convert(datetime, date, 103)</pre>

when i run above query i am getting below error

Error converting data type varchar to datetime.
Posted
Comments
Richard MacCutchan 14-Oct-16 3:28am    
Why are you trying to convert? SQL can compare date time values.
Member 12363094 14-Oct-16 3:34am    
because i have to get between data of startdate and enddate which are datetime
and date column is varchar type

without conversion also i am getting below error
Error converting data type varchar to datetime.
Mehdi Gholam 14-Oct-16 3:53am    
Check the data in your columns for valid date string values.
F-ES Sitecore 14-Oct-16 4:15am    
This is one of the many reasons why you don't store dates as text\varchar. Change your database schema so that date is a datetime or date field as appropriate. This could be rubbish data in your date column, it could be a location issues....we don't know as we can't access your database but using the correct field types eliminates these problems.
Member 12363094 14-Oct-16 4:20am    
Actually above one is in sp
@startDate,@EndDate are input parameters with datatype as datetime

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900