-2

I am using SQL Server 2008 and Microsoft Visual Studio 2008. I have a database table which contains a column for data and time as string. In that column I have both date and time. In my application I have to select date and based on that dateI. I have to get the data from table and show data grid view control.

So I want to compare only with date.

And I referred the below link. But it is not working for me.

Use of SUBSTRING function in where clause

I tried this query, but it's not working for me.

SELECT * 
FROM tAerator 
WHERE SUBSTRING(fldAEdnt, 0, 10) = '07-07-2015' 

Can you please give me way to solve this problem?

Thanks & regards

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Suji D
  • 1
  • 1
  • 2
  • 1
    related: http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype -- besides, why would you store a timestamp as a varchar? – C8H10N4O2 Jul 09 '15 at 12:25
  • what happens? do you get an error? – A ツ Jul 09 '15 at 12:27
  • 1
    Fine answers, but really the problem is not here. Why on earth do you allow dates to be stored as strings? – Steve Jul 09 '15 at 12:34

2 Answers2

1

try this

SELECT * FROM tAerator WHERE Convert(date,fldAEdnt)='2015-07-07'
Sachu
  • 7,555
  • 7
  • 55
  • 94
0
SELECT * FROM tAerator WHERE SUBSTRING(fldAEdnt,1,10)='07-07-2015'

Changed 0 to 1, because in sql server string beginning index is 1

HarryQuake
  • 163
  • 1
  • 13