Should I comment correctly on this fragment of my request?

It seems to me that it deserves a good comment, but I feel that what I have is just distracting.

  • Does this mean a comment?
  • If so, can this comment be improved?

Please note that I am working with a poorly normalized application.

(   
    /* Remove Time Portion From ActivityDate */  
    DateAdd(Day, DateDiff(Day, 0, Activity.ActivityDate), 0) Not Between        
    /* Remove Time Portion From @MinimumDate Or SQL Server Min DateTime */   
    DateAdd(Day, DateDiff(Day, 0, Coalesce(@MinimumDate, '1753-01-01')), 0) And
    /* Remove Time Portion From @MaximumDate Or SQL Server Max DateTime */  
    DateAdd(Day, DateDiff(Day, 0, Coalesce(@MaximumDate, '9999-12-31')), 0) 
)
+3
source share
4 answers

I would pack the dateadd / dated into a scalar udf with a self-commenting name, and then pass in Activity.ActivityDateor Coalesce(@MinimumDate, '1753-01-01'))as parameters

So, you will have the following:

(   
    dbo.ufnGetDateOnly (Activity.ActivityDate) NOT BETWEEN        
         dbo.ufnGetDateOnly (COALESCE(@MinimumDate, '1753-01-01')) AND
         dbo.ufnGetDateOnly (COALESCE(@MaximumDate, '9999-12-31')) 
)

You can also have a "date if null" parameter and work with COALESCE in udf if it's common enough in SQL code

(   
    dbo.ufnGetDateOnly (Activity.ActivityDate, DEFAULT) NOT BETWEEN        
         dbo.ufnGetDateOnly (@MinimumDate, '1753-01-01') AND
         dbo.ufnGetDateOnly (@MaximumDate, '9999-12-31') 
)

Now this is obvious ... no?

+1
source

, , removes X from Y increments X by Y ..

, , . , ? , , , , .

, , , , . - , - , , , .

, , , . , , . , , , , .

+3

, , , . , , , .

0

, . , . :

  • , ? (, , )
  • , ( ?, ? ?)
  • , ? (, , XML-, , EBDIC)
  • ? ?
  • ( , , , ?)
  • (, , )
  • (, , , )
0

Source: https://habr.com/ru/post/1754318/


All Articles