I want merge the entire row after that next row display the result - vb.net

The actual output is:
|ctrcode|ctrname|empcode|empname|ewt |percent%|
|_______|_______|_______|_______|____|________|
|1 |Chain |1001 |A |25.6|15 |
|_______|_______|_______|_______|____|________|
|2 |Chain |1002 |B |15.6|10 |
|_______|_______|_______|_______|____|________|
but I want:
|empcode|empname|ewt |percent%|
|_______|_______|____|________|
|Chain |
|_____________________________|
|1001 |A |25.6|15 |
|_______|_______|____|________|
|1002 |B |15.6|10 |
|_______|_______|____|________|
How do I get it to look like this? I have used a DataGridView and filled the grid.

DataGridView is not able to merge cells, as far as I know. Please see this thread, to find an alternative solution: https://social.msdn.microsoft.com/Forums/windows/en-US/fea3dcff-5447-450a-8f7c-bb1c4f63371d/merging-cells-in-datagridview?forum=winformsdatacontrols
Have a nice weekend.

Related

How can I query CSV values and output them as a table?

We deal with a lot of different kinds of CSV files. All the CSV files are slightly different, but they all have a sort of primary key that is constant across all of them .I have a database that stores the data from these CSVs in Postgresql (11.10) that looks roughly like this:
Files
+--+----+--------+
|id|name|headers |
+--+----+--------+
|1 |file|pk,b,c |
+--+----+--------+
|2 |ifle|pk,b,d,e|
+--+----+--------+
|3 |life|pk,e,f,g|
+--+----+--------+
|................|
Records
+--+------+---------+--------+
|id|fileID|record_pk|record |
+--+------+---------+--------+
|1 |1 |1 |1,2,3 |
+--+------+---------+--------+
|2 |1 |1 |1,5,6 |
+--+------+---------+--------+
|3 |1 |7 |7,8,9 |
+--+------+---------+--------+
|4 |2 |1 |1,f,o,o |
+--+------+---------+--------+
|5 |2 |2 |2,b,a,r |
+--+------+---------+--------+
|6 |3 |1 |1,b,a,z |
+--+------+---------+--------+
|............................|
What I'd like to do is query for a single PK within a single file, and get a queryable table of the results. For example, I may want to get data from file 1 for PK 1 from the above. I want the output to be:
+--+-+-+
|pk|b|c|
+--+-+-+
|1 |2|3|
+--+-+-+
|1 |5|6|
+--+-+-+
For another example, I may want to get data from file 2 for PK 2, and the output would be:
+--+-+-+-+
|pk|b|d|e|
+--+-+-+-+
|2 |b|a|r|
+--+-+-+-+
Is such a query actually possible?

Select rows with same id but different result in another column

sql: I have a table like this:
+------+------+
|ID |Result|
+------+------+
|1 |A |
+------+------+
|2 |A |
+------+------+
|3 |A |
+------+------+
|1 |B |
+------+------+
|2 |B |
+------+------+
The output should be something like:
Output:
+------+-------+-------+
|ID |Result1|Result2|
+------+-------+-------+
|1 |A |B |
+------+-------+-------+
|2 |A |B |
+------+-------+-------+
|3 |A | |
+------+-------+-------+
How can I do this?
SELECT
Id,
MAX((CASE result WHEN 'A' THEN 'A' ELSE NULL END)) result1,
MAX((CASE result WHEN 'B' THEN 'B' ELSE NULL END)) result2,
FROM
table1
GROUP BY Id
results
+------+-------+-------+
|Id |Result1|Result2|
+------+-------+-------+
|1 |A |B |
|2 |A |B |
|3 |A |NULL |
+------+-------+-------+
run live demo on SQL fiddle: (http://sqlfiddle.com/#!9/e1081/2)
there are a few ways to do it.
None of tehm a are straight forward.
in theory, a simple way would be to create 2 temporary tables, where you separte the data, all the "A" resultas in one table and "B" in another table.
Then get the results with simple query. using JOIN.
if you are allowed to use some scrpting on the process then it is simpler, other wise you need a more complex logic on your query. And for you query to alwasy work, you need to have some rules like, A table always contains more ids than B table.
If you post your real example, it is easier to get better answers.
for this reason:
ID Name filename
1001 swapan 4566.jpg
1002 swapan 678.jpg
1003 karim 7688.jpg
1004 tarek 7889.jpg
1005 karim fdhak.jpg
output:
ID Name filename
1001 swapan 4566.jpg 678.jpg
1003 karim 7688.jpg fdhak.jpg
1004 tarek 7889.jpg ...
.. ... ... ...

SQL: How to get all descendants from a table with "many-to-many" related columns

I am still exploring SQL, hence I have an apparently easy question.
I have the following table in SQL Server 2008 R2.
As you see, this is a mapping table where there is a "many-to-many" relation between InstrumentIDs and ProductIDs:
|InstrumentID | ProductID |ID(PK)|
|-------------|-------------|------|
|10 |21 |0 |
|10 |22 |1 |
|11 |22 |2 |
|11 |23 |3 |
|12 |24 |4 |
|12 |25 |5 |
|----------------------------------|
I wish to write a query/SP which takes as an input let's say an InstrumentID and returns all the associated mappings extracted recursively.
For example, let's say that I provide InstrumentID = 10. Then, a satisfying result would be:
|InstrumentID | ProductID |ID(PK)|
|-------------|-------------|------|
|10 |21 |0 |
|10 |22 |1 |
|11 |22 |2 |
|11 |23 |3 |
|----------------------------------|
What is the best way of accomplishing this ?
An example would definitely be useful.
I have tried the following query using CTE:
WITH Map
AS (
-- Anchor
SELECT InstrumentID, ProductID
FROM InstrumentProduct
WHERE InstrumentID IN (10)
UNION ALL
-- Recursive
SELECT IP.InstrumentID, IP.ProductID
FROM InstrumentProduct IP
INNER JOIN Map
ON IP.InstrumentID = Map.InstrumentID
OR IP.ProductID = Map.ProductID
)
SELECT *
FROM Map
OPTION (MAXRECURSION 50);
But query is executed with an error: "The statement terminated. The maximum recursion 5 has been exhausted before statement completion."
However the results are returned apparently correct, but duplicated.
Any kind of help and advice is definitely helpful.
Thanks!

How to write an SQL statement to record the fact that Rabbit has one additional homework assigned

I have a table shown below, and I want to record the fact that Rabbit has one additional homework assigned.
id |name |partnerId |totalHW |lateHW |major
-----------------------------------------------
12 |Puma |17 |3 |0 |CS
14 |Rabbit |21 |7 |4 |SE
17 |Mouse |12 |5 |5 |CE
21 |Aardvark |32 |2 |0 |CS
22 |Cougar |24 |4 |2 |SE
24 |Zebra |28 |7 |3 |EE
27 |Orca |14 |2 |1 |CS
32 |Elephant |null |0 |null |S
How do I go about it? I could not find the relation as how is Rabbit assigned one additional homework. How to solve this query?
I would do it like this:
UPDATE [tablename]
SET totalHW = totalHW + 1
WHERE name = 'Rabbit';
You'll likely come to a solution easily if you change to a normalized database structure. "totalHW" and "lateHW" are calculated fields based on other data, i.e., individual assignments. Instead create a homework table, likely with a late field and whatever other fields, and when you need to know total and number of late, calculate that in sql. Once you do that, adding more homework and other manipulation of the data becomes very simple.

Crystal Report SUM function with CASE

I have the following column values in my crystal report:
|Code |Unit |
|A |2 |
|B |3 |
|C |2 |
|D |3 |
|E |1 |
|F |1 |
|G |4 |
|H |(3) |
I want to summarize the Unit except the Units which has Code H,J,K, and L.
The Codes: H,J,K, and L contains units which has parenthesis.
Is there a way to do this?
If you want to exclude any row or value from summary, it can be done by writing your case inside Use a formula field under Evaluate in Running Total Field
Refer the following Image...
The rows or fields which doesn't satisfy the condition will be skipped from Evaluation of summary.
Try this and get back with results !!
If you want to omit only units with ‘(‘ in it just convert this filed to number
Use
Val ({Unit})
this will return 0 for non-numeric text and number for numeric create sum of these you will get what you want
If you want not to use any special then create formula field like this
if {fa_rep_vr_Main.CustomTitle} not in('A','B','C') then
0
else
val({Unit})
use sum of this
If you want sum of NewPriceAD then use it in mentained field