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

  • SEARCH
  • Home
  • 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 9179659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:51:13+00:00 2026-06-17T17:51:13+00:00

in my SQL Query i am Calculating column values by using CASE WHEN THEN

  • 0

in my SQL Query i am Calculating column values by using CASE WHEN THEN ELSE END Condition.
Now i want to find difference between computed column and normal column

My Query

SELECT  T.Ticket [Ticket],
        TT.TicketType [Ticket Type],
        T.Dependency [Dependency],
        CASE 
                WHEN (
                        SELECT  TOP 1 f1.UpdatedOn
                        FROM    TicketTypeFollowUp AS f1
                        WHERE   f1.UpdatedOn < T.UpdatedOn
                                AND f1.Ticket = 61423
                        ORDER   BY f1.UpdatedOn DESC
                    ) IS NULL
                THEN Ticket.TicketRaisedOn
                ELSE (
                        SELECT  TOP 1 f1.UpdatedOn
                        FROM    TicketTypeFollowUp AS f1
                        WHERE   f1.UpdatedOn < T.UpdatedOn
                                AND f1.Ticket = 61423
                        ORDER   BY f1.UpdatedOn DESC
                    )
                END [Start Date],
        T.UpdatedOn [End Date],
        L.EmpName [Updated By]
FROM    dbo.TicketTypeFollowUp T
        LEFT JOIN dbo.Ticket
                ON T.Ticket = Ticket.Code
        LEFT JOIN dbo.TicketType TT
                ON T.TicketType = TT.Code
        LEFT JOIN LoginUser L
                ON T.UpdatedBy = L.Code
WHERE Ticket = 61423

Query Result

Ticket  Type    Dependency  Start Date              End Date                Updated By
61423   FLM     AGS         2013-01-22 15:50:08.757 2013-01-22 18:35:50.893 Kedar S

I want one more column which displays End Time - Start Time I have used CASE hence i am unable to compute difference.

Database is SQL SERVER 2008

  • 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-06-17T17:51:15+00:00Added an answer on June 17, 2026 at 5:51 pm

    You can use your current query as a CTE or a derived table. Here is an example using a CTE:

    ;WITH CTE AS
    (
        -- your current query here
    )
    SELECT *, DATEDIFF(MINUTE,[Start Date],[End Date]) [End Time - Start Time]
    FROM CTE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using oracle as my back end and i write insert query as
Can anyone post a SQL query for Calculating Total No. of Orders per Day?
Anyone knows how to built temp table of week using T-SQL query? I heard
I need to fetch a number of rows between two column values, using a
I'm having some performance problems where a SQL query calculating the average of a
I am trying to get a sequential number column returned with my sql query.
I have a troublesome SQL query that I'm trying to make using Entrinsik's Informer.
I need report from multi table I use this query (SQL Server) Select CASE
I am getting and calculating some basic order information in my SQL query. I
SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles

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.