Search code examples
stored-proceduressql-server-2000

What does this code line is doing


In reference to my question,

Converting a big stored procedure into a view

In SP i have this code line,

@countCrates = COUNT(DISTINCT ISNULL(countCratesAddress, 'EMPTY')) , @FirstCrateAddres = MIN(countCratesAddress)

Not sure what it's doing or how to debug it.


Solution

  • Somewhere in the SP, this variable is assigned to some values or select "countCratesAddress". Then its used.

    The Breakdown is:

    > @FirstCrateAddres = MIN(countCratesAddress).
    

    ** get minimum of countCratesAddress and assign to the variable '@FirstCrateAddres'

    > COUNT(DISTINCT ISNULL(countCratesAddress, 'EMPTY')).
    

    ** if "countCratesAddress" is null, replace it with the word "EMPTY" then take the COUNT of what comes back from the DISTINCT of "countCratesAddress"