Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6703321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:09:27+00:00 2026-05-26T07:09:27+00:00

Im having an issue with a Stored Procedure I have written, I can call

  • 0

Im having an issue with a Stored Procedure I have written, I can call it in management studio and it works fine, yet calling it from my codebehind gives this error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. when i call da.Fill(dt)

What is really puzzling me here is that I dont actually convert anything from varchar to datetime, the most I do with the date variables is format them into a different datetime format.

My VB.Net code

  Private Function dbGetEvents(ByVal start As DateTime, ByVal days As Integer) As DataTable
      Dim dt As New DataTable()

      Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())

      Dim cmd As New SqlCommand
      cmd.CommandType = CommandType.StoredProcedure
      cmd.CommandText = "spGetEventDetails"
      cmd.Parameters.AddWithValue("@start", start)
      cmd.Parameters.AddWithValue("@end", start.AddDays(days))
      cmd.Parameters.AddWithValue("@userid", ddlUser.SelectedValue)

      cmd.Connection = conn

      Using da As New SqlDataAdapter(cmd)
         conn.Open()
         da.Fill(dt)
         conn.Close()
      End Using

      Return dt
   End Function

My SQL Procedure:

CREATE PROCEDURE spGetEventDetails
(
    @start AS DATETIME,
    @end AS DATETIME,
    @userid AS INT
)
AS
BEGIN

SET @start = CONVERT(CHAR(10), CAST(@start AS DATETIME), 23)
SET @end = CONVERT(CHAR(10), CAST(@end AS DATETIME), 23)

    -- GET DETAILS FOR TICKETS
    SELECT
        [ev].[id]                           AS [EventID],
        CAST([tck].[TicketID] AS NVARCHAR)  AS [TicketID],
        [tck].[Description]                 AS [Description],
        [ev].[eventstart]                   AS [Start],
        [ev].[eventend]                     AS [End],
        [ev].[status]                       AS [Status],
        [ev].[type]                         AS [EventType],
        CAST([tck].[Type] AS NVARCHAR)      AS [Type],
        CAST([tck].[Product] AS NVARCHAR)   AS [Product],
        CAST([tck].[Severity] AS NVARCHAR)  AS [Severity],
        [ev].[resource_id]                  AS [resource_id],
        CAST(pers.FirstName AS NVARCHAR)    AS [FirstName],
        CAST(pers.Surname AS NVARCHAR)      AS [Surname],
        CAST(tck.LogDate AS NVARCHAR)       AS [LogDate]
    FROM
        tblSupportEvent ev
    JOIN
        tblTicketsInEvents tie
    ON
        ev.id =tie.eventID
    JOIN
        SupportTicketsTbl tck
    ON
        tie.ticketID = tck.TicketID 
    JOIN 
        PersonnelTbl pers
    ON
        pers.ID = tck.LoggedBy 
    WHERE
        ev.type = 1
    AND 
        NOT (([eventend] <= @start) OR ([eventstart] >= @end))  
    AND  
        resource_id <> 0  
    AND   
        ev.resource_id = @userid  

UNION 
    -- GET THE DETAILS FOR NON TICKET ITEMS

    SELECT
        [ev].[id]           AS [EventID],
        ''                  AS [TicketID],
        [nti].[Description] AS [Description],
        [ev].[eventstart]   AS [Start],
        [ev].[eventend]     AS [End],
        [ev].[status]       AS [Status],
        [ev].[type]         AS [EventType],
        ''                  AS [Type],
        ''                  AS [Product],
        ''                  AS [Severity],
        [ev].[resource_id]  AS [resource_id],
        ''                  AS [FirstName],
        ''                  AS [Surname],
        ''                  AS [LogDate]
    FROM
        tblSupportEvent ev
    JOIN
        tblNonTicketsInEvents nte
    ON
        ev.id = nte.eventID 
    JOIN
        tblNonTicketItems nti
    ON
        nte.nonTicketID = nti.id    
    WHERE
        ev.type = 2
    AND
        NOT (([eventend] <= @start) OR ([eventstart] >= @end))  
    AND  
        resource_id <> 0  
    AND   
        ev.resource_id = @userid  
END

I cant see where this error could be coming from, having tested running it in SQL management studio without error I am pretty sure the error is in the VB.

My first thought was that maybe the parameter I am passing in the @start / @end values arent being recognised as DateTime so I tried adding the parameters like:

 Dim p As New SqlParameter

  p.SqlDbType = SqlDbType.DateTime
  p.ParameterName = "@start"
  p.Value = start
  cmd.Parameters.Add(p)

but this just gives me the same result. If anyone can suggest where I am going wrong id be gratefull.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:09:28+00:00Added an answer on May 26, 2026 at 7:09 am

    The language of the logins is probably different.

    set dateformat mdy
    
    declare @start datetime = '20110130'
    
    SET @start = CONVERT(CHAR(10), CAST(@start AS DATETIME), 23)
    

    Works. But set dateformat dmy doesn’t.

    To extract the date part of a datetime you can use DATEADD(DAY,DATEDIFF(DAY,0,@start),0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue trying to call a web service from stored procedure. sp_OACreate
I'm having a never-ending problem with trying to call a stored procedure from a
I'm having issues when trying to call a MySQL (5.0.77) stored procedure with parameters,
Having an issue here that I have tried everything I can think of but
I'm having an issue trying to set variable in SQL in a stored procedure.
I am having an issue with a stored procedure. I am trying to merge
Can't find the solution. I'm having the following stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_process_upload_log`(
I am having difficulty executing a MS SQL Server stored procedure from Java/jsp. I
I have a stored procedure that takes data from multiple tables. The stored procedure
I am having issues with the following stored procedure query. I have 3 tables:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.