Advertisement

10.30.2007 at 03:18PM PDT, ID: 22928530
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

Formatting Dates in SQL Server 2005

Asked by irfo in SQL Query Syntax, MS SQL Server, Microsoft Visual Basic.Net

Tags: , , ,

Hello,

I have an issue where i need to format dates in an SQL Server 2005 stored procedure where dates are currently being passed in as 'dd-MM-YYYY hh:mm:ss' and i think that i need them to be passed in as 'YYYY-MM-dd hh:mm:ss'

Just to provide a little background on what i am doing. I am currently using an assembly in SQL server to update records in exchange server. This assembly is linked to a stored procedure and i have another stored procedure passing values into the assembly linked SP by using a cursor to get values from a table.

Code example calling the Assembly SP is as follows:
_____________________________________________________

ALTER proc [dbo].[spExchangeAppUpdateDeleteInsert] as
-- =============================================
-- Declare and using a READ_ONLY cursor
-- =============================================
DECLARE WorkCursor CURSOR
READ_ONLY
FOR SELECT [ExchangeAppPendingId]
      ,[ExchangeId]
      ,[Subject]
      ,[Location]
        --,[StartDate]
        --,[EndDate]
        ,convert(nvarchar(19),[StartDate],120) as StartDate
        ,convert(nvarchar(19),[EndDate],120) as EndDate
        ,[MessageBody]
      ,[Action]
      ,[Completed]
  FROM [eSAY_MSCRM].[dbo].[tExchangeAppPendingActions]
  WHERE Completed is null
 

DECLARE @ExchangeAppPendingId int
DECLARE @ExchangeId uniqueidentifier
DECLARE @Subject varchar(100)
DECLARE @Location varchar(100)
DECLARE @StartDate Datetime
DECLARE @EndDate Datetime
DECLARE @MessageBody varchar(100)
DECLARE @Action varchar(40)
DECLARE @Completed bit

OPEN WorkCursor


FETCH NEXT FROM WorkCursor INTO @ExchangeAppPendingId,
      @ExchangeId,
      @Subject ,
      @Location ,
      @StartDate,
      @EndDate,
      @MessageBody,
      @Action ,
      @Completed


WHILE (@@fetch_status <> -1)
BEGIN
      IF (@@fetch_status <> -2)
      BEGIN
--            PRINT 'add user defined code here'
--            eg.
            DECLARE @message varchar(100)
            SELECT @message = 'Appointment is: ' + @Action
            PRINT @message
            PRINT @StartDate

--            If @Action = 'Update'
--            begin
--                  exec dbo.sp_UpdateExchApp @Subject, @Location, @StartDate, @EndDate, @MessageBody, @ExchangeId
--                  
--            end

            if @Action = 'Delete'
            begin
                  exec dbo.sp_DeleteExchApp @ExchangeId
            end

            if @Action = 'Insert'
            begin
                  Print @StartDate
                  select @MessageBody = [Description] from dbo.ActivityPointerBase where ActivityId = @ExchangeId
                  select @Location = Location from dbo.AppointmentBase where ActivityId = @ExchangeId
                  exec dbo.sp_AppCreate @Subject, @Location, @MessageBody, @StartDate, @EndDate

                  --exec dbo.sp_AppCreate 'Test', 'Tets','Test', '2007-10-30 20:00:00', '2007-10-30 20:30:00'
            end


      END

      update [eSAY_MSCRM].[dbo].[tExchangeAppPendingActions]
            set completed = 1
      where ExchangeAppPendingId =@ExchangeAppPendingId

      FETCH NEXT FROM WorkCursor INTO @ExchangeAppPendingId,
            @ExchangeId,
            @Subject ,
            @Location ,
            @StartDate,
            @EndDate,
            @MessageBody,
            @Action ,
            @Completed
END

CLOSE WorkCursor
DEALLOCATE WorkCursor
________________________________________________________

When i try to execute the assembly manually (commented out line with static values) the assembly works fine. But when i try to get the assembly to update from the sp passing in the values from the table i get an error.
'The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.'
and the format of the dates in the table are 'dd-MM-yyyy hh:mm:ss'.
As you can also see from the commented out lines at the select part of the SP i have tried the CONVERT function with no success.

So can sombody help me out.

PS, Let me know if i need to clear any of this up.

Thanks in advanced.


Start Free Trial
[+][-]10.30.2007 at 03:22PM PDT, ID: 20181656

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 03:24PM PDT, ID: 20181665

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 03:28PM PDT, ID: 20181693

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 04:04PM PDT, ID: 20181850

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 05:44PM PDT, ID: 20182225

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 05:51PM PDT, ID: 20182255

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 06:01PM PDT, ID: 20182299

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 06:07PM PDT, ID: 20182321

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 06:24PM PDT, ID: 20182358

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 06:31PM PDT, ID: 20182377

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server, Microsoft Visual Basic.Net
Tags: sql, server, 2005, date
Sign Up Now!
Solution Provided By: dtodd
Participating Experts: 4
Solution Grade: B
 
 
[+][-]10.30.2007 at 06:34PM PDT, ID: 20182385

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 07:03PM PDT, ID: 20182476

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 07:52PM PDT, ID: 20182613

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.30.2007 at 10:41PM PDT, ID: 20183066

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.31.2007 at 05:46PM PDT, ID: 20190210

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628