Need help with Conditions in SQL Query

  • I'm only listing snippets of the query which are sub queries.

    Below sub query displays the month if a certain task (TaskID 1) is closed on the same month or displays "0" if it is not closed in the same month. Plus it displays the activity note in detail for that ONE task(Task ID 1). this is all working fine for me

    (SELECT Top 1 case when Month(TaskFinish)=Month(TaskSTart) THEN Month(TaskStart) ELSE '0' END

    FROM Tasks T

    WHERE ticketid = 140 And TaskID=1 AND ttype =1

    ORDER BY TaskSTart desc) [TaskStartClosedMonth],

    (SELECT Top 1 Response

    FROM Tasks T

    INNER JOIN Response2 R ON R.QAssignID=AssignID

    WHERE T.ticketid = 140 And T.TaskID=1 AND ttype =1 ) [ResponseDetail],

    The above queries is for only ONE Task. I need to incorporate 3 tasks

    I need to display the month for ANY of the THREE tasks (TaskID1,TaskID2,TaskID3) that were started and closed in same month, if no match found then display 0.

    If it finds a match say for TaskID 2 , then give me the response for TaskID 2.

    In TSQL it would have been listtle easy to do that but I need to get this done in SQL query. I believe we will have Case satements and conditions?

    please advise

  • What do you mean by this?

    shezi (8/26/2016)


    In TSQL it would have been listtle easy to do that but I need to get this done in SQL query. I believe we will have Case satements and conditions?

    please advise

    Why not just change the conditions on your subqueries? Why don't you remove the subqueries from the column list?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I'm not sure how to setup conditions to satisfy my requirement. Can you show me an example.

    Thanks

  • You know, it is really hard to offer assistance when we don't even see the whole query.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply