How to normalize the null column? [duplicate] - sql-server

This question already has answers here:
How can you represent inheritance in a database?
(7 answers)
What is the best way to implement Polymorphic Association in SQL Server?
(9 answers)
How do you effectively model inheritance in a database?
(9 answers)
Closed 8 months ago.
I have object
{
totalPrice : 20,
totalCost : 15,
invoice:{ [ { price : 10, name : "microphone" }, { price : 10, name : "speaker" } ] },
order: { [ { price : 10, description : "microphone" }, { price : 10, description :"speaker" } ] }
}
I want to create rules and store in database
rule1 totalPrice > 10
rule2 totalPrice > totalCost
rule3 invoice.price > order.price where invoice.name = order.description
the initial data as table will be
RuleId
WorkFlowFieldId1
Operator
Value
WorkFlowFieldId2
Matching
1
F1
More Than
10
NULL
NULL
2
F1
More Than
NULL
F2
NULL
3
F3
More Than
NULL
F4
F5,F6
so I create
RuleTable
RuleId
WorkFlowFieldId1
Operator
Value
WorkFlowFieldId2
1
F1
More Than
10
NULL
2
F1
More Than
NULL
F2
3
F3
More Than
NULL
F4
MatchConditionTable
RuleId
Key1
Key2
3
F3
F4
when query it should query all rules for the object
The question is there are fields (Value,WorkFlowFieldId2) that can be NULL for some cases
Is it okay to separate into 2 tables?
like
ConstantRule
RuleId
WorkFlowFieldId1
Operator
Value
1
F1
More Than
10
FieldRule
RuleId
WorkFlowFieldId1
Operator
WorkFlowFieldId2
1
F1
More Than
F2
2
F3
More Than
F4

Related

Read excel and populate 2 dimensional array in typescript

i would like to read a simple table in an excel sheet (x rows, y cols) and populate a 2 dimensional array in typescript. Something like below:
client_id orderid
1 : 12 3 45 78 97
2 : 67 89 12
3 : 7 90 23
Do you know a good excel library ? Thank you
regards,
Titi
You just need to specify the table name and then you can use getRange().getValues() to capture the values within the table as a 2 day array. Example:
function main(workbook: ExcelScript.Workbook) {
const theTableName:string = "table1"; // or whatever the name is
var theTable = workbook.getTable(theTableName);
var allValues = theTable.getRange().getValues();
// allVallues is now an 2-day array with values
}

ms-sql return max variable by group identifier [duplicate]

This question already has answers here:
Selecting a Record With MAX Value
(5 answers)
Retrieving last record in each group from database - SQL Server 2005/2008
(2 answers)
Closed 3 years ago.
I have a table as follows :
ID HC Week
1 2 1
1 0 2
2 14 1
2 12 2
3 9 1
3 0 2
the data is generated by (what I believe to be) a complex query.
now what I'm trying to do is wrap this in a sub query and only return the max HC column by ID with its corresponding week.
the best I can do is wrap a max function and group it by ID and pass in theMAX(HC) function as such
SELECT
max(HC),
ID
from (sub query)
group by
ID
this gets me very close, but I also want the corresponding week when I pass this in it returns the above table with every key.
SELECT
max(HC),
ID,
Week
from (sub query)
group by
ID,
Week
what I'm after is the following :
ID HC Week
1 2 1
2 14 1
3 9 1
is anyone able to guide me ?

Checking existing values in database at the same time

I have two tables: CB and Obj
CB
CBID CharaID Key Part
1 1 1
1 2 1
1 3 0
1 4 0
1 5 1
Obj
ObjID CharaID CharaValue
1 1 TestOne
2 2 TestTwo
3 3 TestThree
4 4 TestFour
5 5 TestFive
And I have two parameters that are send through c#.
#CBID and #CharaValue.
I need to join these two tables through CharaID column.
In table CB there is column Key part. When the value is 1 I need to check IF there is a same value that is send trough the two parameters with the values in the CharaValue column.
Example:
#CBID and #CharaValue send values for CharaID = 1 are 1 and TestOne and for CharaID = 2 are 2 and TestTwo. They both have Key Part 1 and I need to check if there is allready duplicate string values in Obj table, CharaValue column, bouth at the same time.
Can someone help me with the stored procedure to do this ?
I created some part but I need the rest...
#CBID int,
#CharaValue nvarchar(50)
SELECT a.CharaID, b.CharaValue
FROM CB AS A,
INNER JOIN Obj AS B ON a.CharaID = b.CharaID
WHERE "Key Part" = 1...

Is it possible to use json_populate_recordset in a subquery?

I have a json array with a couple of records, all of which have 3 fields lat, lon, v.
I would like to create a select subquery from this array to join with another query. The problem is that I cannot make the example in the PostgreSQL documentation work.
select * from json_populate_recordset(null::x, '[{"a":1,"b":2},{"a":3,"b":4}]')
Should result in:
a | b
---+---
1 | 2
3 | 4
But I only get ERROR: type "x" does not exist Position: 45
It is necessary to pass a composite type to json_populate_recordset whereas a column list is passed to json_to_recordset:
select *
from json_to_recordset('[{"a":1,"b":2},{"a":3,"b":4}]') x (a int, b int)
;
a | b
---+---
1 | 2
3 | 4

How to store testing options into database?

Let's say I have some parameters such as a,b,c, and I need to store the test results by changing them.
The thing is that the the number of parameters will be keep increasing, so I can't keep them as static column.
For example :
Test 1 : a = 10, b = 20, c = 1
Test 2 : a = 11, b = 21, c = 11
Test 3 : a = 11, b = 20, c = 1
...
Test 1001 : d = 30
I thought about having a table for parameters as follows.
id name value
1 a 10
2 b 20
3 c 1
4 a 11
5 b 21
6 c 11
...
100 d 30
And a table for using the option. The orders are not important.
id usage
1 1-2-3
2 4-5-6
3 4-5-3
The problem for this approach is that the number of the option used for each test is not fixed. It can be 1, but it also can be 1-2-3-4-5-6-7.
Questions
Is there any better method for this problem? Not using two tables or someting?
If I have to use this method, how can I deal with the variable element problem? Use string or equivalent?
Take a look at this discussion.

Resources