Question : MS SQL Serial Date

Hi All,

I am changing my web DB from Access db to MS SQL Server.  I naively thought it would be as simple as importing the data from access, changing the connections and away we go.

The problem is, some of the queries I am using with Access don't work with MS SQL Server.  In one of my access queries i'm using int and also I am subtracting 30 days from Now.  But when I try to run this I receive numerous errors; int isn't a funtion, now isn't a function and so on.

Here is the query, what do I have to change to get it to run with SQL Server?

Select Count(Date_Added) AS CountOfDate_Added FROM tblPlaces WHERE Active <> 0 AND Int(Date_Added) >= now()-30;

thanks.

Answer : MS SQL Serial Date

Hi kerrybenno,

If it is not an issue if the statement performs a full table scan, to make your statement similar to you original Access query you can easily get rid of the time part of your datetime columns.  Here's a link that provides you with a user-defined function in getting just the date part of a datetime parameter:

http://www.sql-server-helper.com/functions/get-date-only.aspx

To use this in your query:

Select Count(Date_Added) AS CountOfDate_Added
FROM tblPlaces
WHERE Active <> 0 AND
[dbo].[ufn_GetDateOnly](Date_Added) >= [dbo].[ufn_GetDateOnly](DATEADD(DD, -30, GETDATE()))

Since a function is used with your Date_Added column, if your table has any index on this table that index will not be used and a full table scan will be performed to execute your query.

Hope this helps.

Random Solutions  
 
programming4us programming4us