Sql_numskull
Sql_numskull

Reputation: 5

SQL - Display fixed message based on query result

I am new to SQL so please go easy on me if this has been asked before (I couldnt find my answer)

Question: I have written a query

SELECT Name, 
       DATEDIFF (DAY, GETDATE(), Date_D) AS DR
FROM Project
WHERE Date_D < GETDATE()

What I want to achieve is the result of the query should list the Name and then say "completed" alongside it

Outcome

Name    DR
A    Completed
B    Completed

please can someone kindly explain how this is done.

Many thanks

Upvotes: 0

Views: 170

Answers (2)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

it seems based datediff you want to put a comment , you can use case when if that is your requirement

SELECT Name, 
       case when ( DATEDIFF (DAY, GETDATE(), Date_D))<0 then 'completed' else null end AS DR
FROM Project
WHERE Date_D < GETDATE()

Upvotes: 1

Pham X. Bach
Pham X. Bach

Reputation: 5442

You could just use this is enough:

SELECT Name, 
       'Completed' AS DR
FROM Project
WHERE Date_D < GETDATE();

Upvotes: 1

Related Questions