return int (urgent) [modified]
-
Hellow everybody I want a query that will return number of rows in the database , but it will take three parametes from the calling method. I implemented a query which is as follows: Select Count(*) From MainRecord Where (MealType = @MealType) AND (ID = @ID) AND ( CAST(FLOOR(CAST(DATE AS FLOAT)) AS DATETIME = @DATE) The purpose of this query is that I want to count number of rows if the ID, MealType and DATE are in the database. Also, the @DATE I am giving in the calling query is now date which is for example ( today date [08/23/2007 00:00:00]). I wanted to be checked with the date that is stored in the database where the DATE that is stored in the database is DATETIME which is in this form (08/22/2007 13:14:50). Therefore, the CAST(FLOOR(CAST(DATE AS FLOOT)) AS DATETIME will convert that datetime to (08/22/2007 00:00:00) so we could compare then just in the date. I don’t know if this way is right or not and if not how can I do it. Thaanks, -- modified at 11:36 Thursday 23rd August, 2007
-
Hellow everybody I want a query that will return number of rows in the database , but it will take three parametes from the calling method. I implemented a query which is as follows: Select Count(*) From MainRecord Where (MealType = @MealType) AND (ID = @ID) AND ( CAST(FLOOR(CAST(DATE AS FLOAT)) AS DATETIME = @DATE) The purpose of this query is that I want to count number of rows if the ID, MealType and DATE are in the database. Also, the @DATE I am giving in the calling query is now date which is for example ( today date [08/23/2007 00:00:00]). I wanted to be checked with the date that is stored in the database where the DATE that is stored in the database is DATETIME which is in this form (08/22/2007 13:14:50). Therefore, the CAST(FLOOR(CAST(DATE AS FLOOT)) AS DATETIME will convert that datetime to (08/22/2007 00:00:00) so we could compare then just in the date. I don’t know if this way is right or not and if not how can I do it. Thaanks, -- modified at 11:36 Thursday 23rd August, 2007
CanadianBoy wrote:
FLOOT
Did you mean
FLOAT
?CanadianBoy wrote:
I don’t if this way is right or not and if not how can I do it.
Have you tried experimenting? Building up a part of the query to see if it does what you want?
SELECT GETDATE()
SELECT CAST(GETDATE() AS FLOAT)
SELECT FLOOR(CAST(GETDATE() AS FLOAT))
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)Looks like it works to me.
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live. Upcoming FREE developer events: * Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ... * Reading: SQL Bits My website
-
CanadianBoy wrote:
FLOOT
Did you mean
FLOAT
?CanadianBoy wrote:
I don’t if this way is right or not and if not how can I do it.
Have you tried experimenting? Building up a part of the query to see if it does what you want?
SELECT GETDATE()
SELECT CAST(GETDATE() AS FLOAT)
SELECT FLOOR(CAST(GETDATE() AS FLOAT))
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)Looks like it works to me.
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live. Upcoming FREE developer events: * Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ... * Reading: SQL Bits My website
-
Yes, I mean foat. Does this way logical and it will work properly. If there is an other way i can try especially to check the time. -- modified at 11:53 Thursday 23rd August, 2007
There is another way to check the date.. try this.. Select * From .... Where Convert(DateTime, @ParameterDate, 103) = Convert(DateTime, GetDate(), 103) This is for checking with current date(GetDate()). For more precision yo can add the following lines of code with the above code. And Year(@ParameterDate) = Year(GetDate()) And Month(@ParameterDate) = Month(GetDate())
The name is Sandeep
-
There is another way to check the date.. try this.. Select * From .... Where Convert(DateTime, @ParameterDate, 103) = Convert(DateTime, GetDate(), 103) This is for checking with current date(GetDate()). For more precision yo can add the following lines of code with the above code. And Year(@ParameterDate) = Year(GetDate()) And Month(@ParameterDate) = Month(GetDate())
The name is Sandeep