Quantcast
Channel: SCN : Unanswered Discussions - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 3719

custom function issue

$
0
0

Hi guys

i am getting problem with the custom function... the problem is that sometime custom function works fine but sometime it doesn't do what it is suppose to do ... see the below mentioned sample table and script written...

 

In below mentioned sample data wd_new is the new field which gets created using the script shown below.. you can see that for id 101 script worked fine.. but for id 102 it didn't...

 

please help me to rectify what i am doing wrong...

 

CREATE TABLE #t (id INT,dt1 datetime, wd int, wd_new int)

INSERT INTO #t VALUES (101,'2011-12-20','','431')
INSERT INTO #t VALUES (101,'2011-12-20','431','431')
INSERT INTO #t VALUES (101,'2011-12-28','','544')
INSERT INTO #t VALUES (101,'2011-12-28','544','544')
INSERT INTO #t VALUES (101,'2011-12-28','544','544')
INSERT INTO #t VALUES (101,'2011-12-28','544','544')
INSERT INTO #t VALUES (101,'2012-01-24','431','431')
INSERT INTO #t VALUES (101,'2012-01-24','','431')
INSERT INTO #t VALUES (101,'2012-01-24','431','431')
INSERT INTO #t VALUES (101,'2012-01-30','','544')
INSERT INTO #t VALUES (101,'2012-01-30','544','544')
INSERT INTO #t VALUES (102,'1998-03-25','','')
INSERT INTO #t VALUES (102,'2002-12-09','483','483')
INSERT INTO #t VALUES (102,'2005-08-11','','')
INSERT INTO #t VALUES (102,'2005-08-11','538','538')
INSERT INTO #t VALUES (102,'2009-12-21','534','534')
INSERT INTO #t VALUES (102,'2011-02-14','534','534')
INSERT INTO #t VALUES (102,'2011-06-06','534','534')


select * from #t


if ($cur_dt1 = $prev_dt1 AND $cur_id = $prev_id )
begin
$cur_wd = $prev_wd;
if ($cur_wd is not null)
$prev_wd = $cur_wd ;
end
else
begin
$prev_wd = $cur_wd ;

end
$prev_dt1 = $cur_dt1;
$prev_id = $cur_id;


Viewing all articles
Browse latest Browse all 3719

Trending Articles



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