Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Populate Indicator using sql query

Author  Topic 

rsmohankumar
Starting Member

11 Posts

Posted - 2015-01-06 : 23:30:44
Hi,

I have data as below, I want the indicator to be displayed by using timestamps

Id task_id tsk_complete_ts task_due_date Id_end_ts tsk_indicator id_indicator

50 2001 01-01-2015 02-01-2015 10-01-2015 GREEN

50 2002 03-01-2015 04-01-2015 10-01-2015 AMBER

50 2003 07-01-2015 06-01-2015 10-01-2015 RED

50 2004 NULL 09-01-2015 10-01-2015 GREEN

I need to calculate the indicator for the whole id considering all the tasks by using the below conditions,

1) if tsk_complete_ts > id_end_ts, display id_indicator as RED

2) if any task is in RED or AMBER and id got completed before id_end_ts, the display id_indicator as AMBER

3) Else GREEN

I want the id_indicator to be populate dynamically in view without using stored procedure, id_indicator should be common for whole id.

Task indicator also getting populated in the view using the case statement.

Can you let me know if you have any idea to implement the logic.

Thanks in advance.

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2015-01-07 : 04:01:05
you must results or also data send with dinamicalyy
with case when proc

for example

DECLARE
@test int,
@result char(10)

SET @test = 10

SET @result = CASE @test
WHEN 10 THEN
'OK test'
ELSE
'Test is not OK'
END

PRINT @result;

SET @result = CASE
WHEN @test = 10 THEN
'OK test'
ELSE
'Test is not OK'
END

PRINT @result

http://sql-az.tr.gg/
Go to Top of Page
   

- Advertisement -