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
 need to design a function

Author  Topic 

tribhuwan.tiwari
Starting Member

1 Post

Posted - 2012-09-07 : 07:27:24
Hi
I need to desin a fucntion which takes three parameters
calculateTime(@threadStatusId,@fromDate,@toDate)
I have table Report which contains the folowwing data
There are 10 types of possible frmStatusId and toStatusId.

PrdId RptId ThrdId ChngdDate frmStatusId toStatusId
1 101 201 2012-08-01 40 41
1 101 201 2012-08-03 41 56
1 101 201 2012-08-04 56 56
1 101 201 2012-08-06 56 44
1 101 201 2012-08-08 44 47

1 102 202 2012-08-20 40 41
1 102 202 2012-08-22 41 42
1 102 202 2012-08-23 42 47
1 102 202 2012-08-25 47 56

and so on .........

I want to calculate the time in which status of the thread is in 56
Moreover I want it for all dates between fromDate and toDate.
Suppose fromDate='2012-09-01' and toDate='2012-09-04' then result should be like
PrdId RptId ThrdId TimeAssigned Date
1 101 201 ---- 2012-09-01
1 101 201 ---- 2012-09-02
1 101 201 ---- 2012-09-03
1 101 201 ---- 2012-09-04

It means that till the considered date time it spent in state 56.

I am completely new and this looks very complex for me. Kindly help how to do this in function.


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-08 : 17:13:13
sorry your scenario is not clear. the posted output doesnt seem to have much relationship with posted data

post proper data and output and then somebody might be able to help

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -