Jump to content

sql help neede love india


vizagpower

Recommended Posts


;With ResetImageGenFlag_CTE AS
(
SELECT 
ua.ind_no,
a.individual_id,
a.id,a.ff_id,
a.dateEnd,
ua.imagegen_dt,
DATEDIFF(SS,(dateEnd),ua.imagegen_dt) as TimeElapse,
ua.imagegen_flag,
CASE  WHEN DATEDIFF(SS,a.dateEnd,ua.imagegen_dt) <=120 then 0 else ua.imagegen_flag end as [Flag],
ROW_NUMBER() Over(Partition By individual_id Order By [dateEnd] DESC) Rnk
FROM uaimage ua  
INNER JOIN 
( SELECT ff.individual_id,frr.* 
 FROM  uas.fileread_reads frr
INNER JOIN uas.fileread_files ff on frr.ff_id=ff.id
WHERE ff.id in (SELECT id FROM uas.fileread_files WHERE lu_semester=48) and dateEnd is not null ) a ON a.individual_id= ua.ind_no  and ua.doctype = 'RDST'
)

 

---Select *  From  ResetImageGenFlag_CTE Where  Rnk =1 

Select * Into #Imagegen_Temp From  ResetImageGenFlag_CTE  --- File reads with Max DateEND
  Where  Rnk =1

drop table #Imagegen_Temp


SELECT T.individual_id
      ,A.[ind_no]
      ,A.[imagegen_flag],t.dateEnd
      ,A.[imagegen_dt]
      ,datediff(SS,T.dateEnd,A.imagegen_dt)as TimeElapsed
  FROM [UAImage] A INNER JOIN  #Imagegen_Temp T On T.individual_id = A.ind_no
  where A.doctype = 'RDST' 

--- updates the imagegenflag---
Update X
  Set x.[imagegen_flag] = (CASE WHEN  datediff(SS,T.dateEnd,X.imagegen_dt) <= 120 Then 0 Else x.[imagegen_flag]End)
  From [UAImage] X   
  INNER JOIN  #Imagegen_Temp T On T.individual_id = X.ind_no
  WHERE X.doctype = 'RDST'

DROP TABLE #Imagegen_Temp;

ee drop not working any idea ???

Link to comment
Share on other sites

Just now, loveindia said:

two time drop statements pettav endi man???

shall i remove the last one , typed the highlighted in overlook 

Link to comment
Share on other sites

Just now, vizagpower said:

shall i remove the last one , typed the highlighted in overlook 

no man, remove the one in red... you are creating the temp then immediately you are dropping it... how come will you be able to JOIN in the below update man...? 

one more question... are you running these two queries in same proc or different ones man?

Link to comment
Share on other sites

Just now, loveindia said:

no man, remove the one in red... you are creating the temp then immediately you are dropping it... how come will you be able to JOIN in the below update man...? 

one more question... are you running these two queries in same proc or different ones man?

same proc , any problem dude

 

 

Link to comment
Share on other sites

Just now, loveindia said:

no man, just checking... just remove the red DROP TABLE command thats it man....

will try anna , thanks as ever 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...