Posts Tagged ‘MSSQL’

Keeping only the date part in a datetime field inside MS SQL query

Monday, April 14th, 2008

Since I had to google this to find a good way to only use the datepart of a datetime field from my database, I tought you might use this:

convert(datetime,(convert(varchar (11),getDate())))

The source is on http://www.bennadel.com/blog/122-Getting-Only-the-Date-Part-of-a-Date-Time-Stamp-in-SQL-Server.htm, where you can find other smart ways to do it. I found this was the easyest for me.

Conversion failed when converting the varchar value ‘@parameter’ to data type int or something like this

Friday, April 11th, 2008

This is one of the most annoying errors that you now is easy to handle, but always have to google the sollution, because you don’t remember what you did last time to get rid of it.

Stop checking the C# code, the problem is not there. Just remove the quotes from the query string in the stored procedure and it will work just fine:).