Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8808

Re: Query For Linking Activity

$
0
0

Hi Ankit,

 

 

The following script works for me in SBO query generator:

 

 

declare @c int
declare @n int
declare @p int
declare @OCLG table (idx int identity(1, 1), ClgCode int, CntctDate datetime, Details nvarchar(60), prevActvty int)
set nocount on
select @c = T0.ClgCode from OCLG T0 where T0.ClgCode = [%0]
set @p = @c
-- Forwards
while @p is not null     begin          set @n = null;          select @n = ClgCode from OCLG where prevActvty = @p;          if @n is not null               insert into @OCLG select @n, CntctDate, Details, prevActvty from OCLG where ClgCode = @n          set @p = @n;     end
set @n = @c
-- Backwards
while @n is not null     begin          set @p = null;          select @p = prevActvty from OCLG where ClgCode = @n;          if @p is not null               insert into @OCLG select @p, CntctDate, Details, prevActvty from OCLG where ClgCode = @p               set @n = @p;      end
set nocount off
select ClgCode as [Activity], CntctDate as [Date], Details as [Remarks] from @OCLG order by ClgCode

 

This script searches backwards and forwards to include all the activities linked to a particular activity. You can add additional fields to the results by adding the fields to the temp table definition at the top and then adding the same fields to the two insert statements.

 

Kind Regards,

 

Owen


Viewing all articles
Browse latest Browse all 8808

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>