Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. return int (urgent) [modified]

return int (urgent) [modified]

Scheduled Pinned Locked Moved Database
databasetutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    ksaw123
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • K ksaw123

      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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • C Colin Angus Mackay

        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

        K Offline
        K Offline
        ksaw123
        wrote on last edited by
        #3

        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

        X 1 Reply Last reply
        0
        • K ksaw123

          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

          X Offline
          X Offline
          Xandip
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • X Xandip

            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

            K Offline
            K Offline
            ksaw123
            wrote on last edited by
            #5

            Thanks a lot for your reply both of you.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups