"min()" with two parameters



  • The person who worked before me in the company made this code:

    MIN(DATEPART('weekday',[Entrega Data Real]),6)
    

    What does that 6 mean?

    One min() can you have two parameters?



  • No, we have no way of knowing what it means, but by code the result should give maximum 6, that is, if the day of the week is 7 (probably Sunday, depends on the culture used) then it will consider 6 (probably Saturday), but if it is any days below 7, it will consider the day of the week of delivery.

    A function https://docs.microsoft.com/en-us/sql/t-sql/functions/min-transact-sql?WT.mc_id=DOP-MVP-5002397 need to have at least two arguments since it results in a minimum value between two or more of them. If he had only one argument the result would always be himself.

    Note that in this case it is not being used as aggregation and rather a simple expression, only takes the value of a column in a row and compares with the literal 6. This is made line by line, but is not looking for the minimum of all lines, as is probably thinking. It only works to add if you have any clauses in query have something that groups everything. Nothing posted indicates this and even if it is used so the form of the written function would not aggregate correctly.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2