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. Error converting data type nvarchar to datetime

Error converting data type nvarchar to datetime

Scheduled Pinned Locked Moved Database
helpcsharpdatabasequestion
3 Posts 3 Posters 5 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.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi All, I have a stored procedure as below,

    ALTER PROCEDURE [dbo].[usp_Update_Service_Program_Detail]
    @PK_Service_Program_County_RateCap_Detail int,
    @Unit_Type int,
    @Rate_Cap decimal(15,2),
    ----@County int,
    @ModifiedBy nvarchar(50),
    @ModifiedOn datetime=getdate
    AS
    BEGIN

    select '220' 'Col' -- Test statement
    --Logic is here
    END

    But when I am running the stored procedure as below:

    exec usp_Update_Service_Program_Detail @PK_Service_Program_County_RateCap_Detail= 53196434
    , @Unit_Type=1
    , @Rate_Cap=100
    , @ModifiedBy='aaleemmo'
    , @ModifiedOn=getdate

    I am getting the following error:

    Error converting data type nvarchar to datetime at @ModifiedOn=getdate

    Why is it an error, when getdate returns datetime why should I convert it into Datetime again, when I try it, its giving me error. Can anybody please help me what is the way to execute it and I am getting similar problem from my C# code also, can anybody please help me in this regards. Thanks in advance. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

    M U 2 Replies Last reply
    0
    • I indian143

      Hi All, I have a stored procedure as below,

      ALTER PROCEDURE [dbo].[usp_Update_Service_Program_Detail]
      @PK_Service_Program_County_RateCap_Detail int,
      @Unit_Type int,
      @Rate_Cap decimal(15,2),
      ----@County int,
      @ModifiedBy nvarchar(50),
      @ModifiedOn datetime=getdate
      AS
      BEGIN

      select '220' 'Col' -- Test statement
      --Logic is here
      END

      But when I am running the stored procedure as below:

      exec usp_Update_Service_Program_Detail @PK_Service_Program_County_RateCap_Detail= 53196434
      , @Unit_Type=1
      , @Rate_Cap=100
      , @ModifiedBy='aaleemmo'
      , @ModifiedOn=getdate

      I am getting the following error:

      Error converting data type nvarchar to datetime at @ModifiedOn=getdate

      Why is it an error, when getdate returns datetime why should I convert it into Datetime again, when I try it, its giving me error. Can anybody please help me what is the way to execute it and I am getting similar problem from my C# code also, can anybody please help me in this regards. Thanks in advance. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      indian143 wrote:

      @ModifiedOn datetime=getdate

      Try GetDate**()**

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • I indian143

        Hi All, I have a stored procedure as below,

        ALTER PROCEDURE [dbo].[usp_Update_Service_Program_Detail]
        @PK_Service_Program_County_RateCap_Detail int,
        @Unit_Type int,
        @Rate_Cap decimal(15,2),
        ----@County int,
        @ModifiedBy nvarchar(50),
        @ModifiedOn datetime=getdate
        AS
        BEGIN

        select '220' 'Col' -- Test statement
        --Logic is here
        END

        But when I am running the stored procedure as below:

        exec usp_Update_Service_Program_Detail @PK_Service_Program_County_RateCap_Detail= 53196434
        , @Unit_Type=1
        , @Rate_Cap=100
        , @ModifiedBy='aaleemmo'
        , @ModifiedOn=getdate

        I am getting the following error:

        Error converting data type nvarchar to datetime at @ModifiedOn=getdate

        Why is it an error, when getdate returns datetime why should I convert it into Datetime again, when I try it, its giving me error. Can anybody please help me what is the way to execute it and I am getting similar problem from my C# code also, can anybody please help me in this regards. Thanks in advance. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

        U Offline
        U Offline
        User 12234416
        wrote on last edited by
        #3

        Dear Abdul Aleem. i find your error and please try this code.

        create PROCEDURE [dbo].[usp_Update_Service_Program_Detail]
        @PK_Service_Program_County_RateCap_Detail int,
        @Unit_Type int,
        @Rate_Cap decimal(15,2),
        ----@County int,
        @ModifiedBy nvarchar(50),
        @ModifiedOn datetime=getdate
        AS
        BEGIN

        select '220' 'Col' -- Test statement
        --Logic is here
        END

        exec usp_Update_Service_Program_Detail @PK_Service_Program_County_RateCap_Detail= 53196434, @Unit_Type=1
        , @Rate_Cap=100
        , @ModifiedBy='aaleemmo'
        , @ModifiedOn=''

        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