June 15, 2020 at 12:11 pm
Hi,
I've got the following code to select the period where I have active data:
{ FIXED : MAX(IF NOT (ISNULL([Qty in tn])) THEN [Period] END)}
The problem I have is that the Qty in tn is only null when another column [Data Type] = ACT. How do I modify the above code to take into account the second column?
Cheers!
Regards,
Yari
June 15, 2020 at 2:09 pm
Use an AND, is what I think. I'm not quite sure how you're doing this, but when you evaluate the ISNULL(), I assume you can access both the value of Qty and the value of [Data Type]. In that case, you can see ISNULL and [Data Type] = 'Act'.
However, are you sure that there cannot be a null here if there is a different value for [data type]? Or that you want different behavior? It's not quite clear what you mean here.
June 15, 2020 at 3:59 pm
"It Depends". If this is being used in the SELECT list of a query, you can do pretty much as you please and you'll have no problems. If it's a part of the criteria expressed in a WHERE or ON clause, you have to be REALLY care to not make the query Non_SARGable.
From your original post, I'd guess you code snippet is from an item in the SELECT list but we can't know for sure from what you posted. It would be a whole lot more helpful if you'd post the rest of the query.
Yep... I know that you can't normally include a MAX() aggregation in the WHERE or ON clauses but it's amazing what people have done to do just that.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 15, 2020 at 4:22 pm
If this is being used in the SELECT list of a query,
Jeff, if that is part of a SELECT list, what SQL dialect would that be? I don't know what the above is, but T-SQL it is not. Could it be something for SS[AR]S?
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
June 15, 2020 at 10:34 pm
Jeff Moden wrote:If this is being used in the SELECT list of a query,
Jeff, if that is part of a SELECT list, what SQL dialect would that be? I don't know what the above is, but T-SQL it is not. Could it be something for SS[AR]S?
Lordy,,, I totally ignored the "(FIXED:" notation because I thought it was a copy'n'paste error, possibly from some spec. Thanks for pointing that out, Erland.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy