Skip to content

Tag: tsql

Convert simple JSON to SQL SELECT Statement

I have the following JSON: I’m trying to convert to SQL as follows: All i get is an empty resultset (0 rows when it should be 2 rows), what am i doing wrong? Answer Your JSON has square brackets round the whole thing, meaning it is an array (it only has one element) so your OPENJSON starting point will …

SQL All Categorized Possible Combinations

I recently had a rather interesting problem to solve where I needed to construct a list consisting of a combined selection of one choice from each of an arbitrarily defined set of categories, and an aggregated total of a value associated with each choice. The choices within each category are also arbitrarily …

SQL View Select Optional

I have a view that the current output something like this The rules are as follows Each group can only have 2 code and always have a default code vs not a default code. IF default code is not null, then always show the row. Regardless if Non default code has value or not If default code is null, then