Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
AnswerRe: visual studio bookmarks Pin
OriginalGriff15-Jun-15 8:30
mveOriginalGriff15-Jun-15 8:30 
Question.NET streams and the missing link Pin
Rob Philpott15-Jun-15 4:40
Rob Philpott15-Jun-15 4:40 
AnswerRe: .NET streams and the missing link Pin
David A. Gray15-Jun-15 19:15
David A. Gray15-Jun-15 19:15 
QuestionIs there any possibility to perform file upload and download operation for .net 4.0 web API Pin
Member 1138787715-Jun-15 2:45
Member 1138787715-Jun-15 2:45 
AnswerRe: Is there any possibility to perform file upload and download operation for .net 4.0 web API Pin
Eddy Vluggen15-Jun-15 10:22
professionalEddy Vluggen15-Jun-15 10:22 
QuestionHow to make database for a Project Pin
Member 1154201014-Jun-15 21:53
Member 1154201014-Jun-15 21:53 
AnswerRe: How to make database for a Project Pin
Eddy Vluggen14-Jun-15 23:46
professionalEddy Vluggen14-Jun-15 23:46 
AnswerRe: How to make database for a Project PinPopular
CHill6015-Jun-15 5:37
mveCHill6015-Jun-15 5:37 
As Eddy said, you need to normalise this data. You also need to analyse and manipulate it at bit.

Separate things out into information about a specific, physical machine and information about the type of machine.

For example, 'Made in' is going to apply to the Machine Name and Model No. and probably the Supplier that you have in brackets after the machine name. Those things would apply to those machines whichever company owns them. But Serial No. and Location will refer to the specific instances of machines owned by your company.

If this data is in a spreadsheet then move the columns around to make it more obvious.

Second thing to note, as you have pointed out, is that S.No is not unique - Nor is Machine Id. Only you will know what those are meant to represent, but when faced with data like this I just make sure it's recorded, but ignore it for the purposes of building my table linkages.

The implication is that the line with IMPIANTO in it is also 06,CC01, CHip Collector (FIDA), we don't know where it is made nor do we know where it is located. Fill in those gaps as much as you can. It makes it easier to load the data and it also helps to identify re-used words.

Now really start looking at the text itself. Start with Location - for every machine in the "Old Factory" or the "New Factory" you are storing 11 characters. Pull that information out into it's own table so that for each row you only need to store an integer - a foreign key - that "points" to information in a Location table. This also gives you the opportunity to store other information about each Location - an address, GPS, site contact number etc. For example:
SQL
-- These are specific to your company
-- Where individual machines can be physically present
create Table Location
(
	LocId int identity(1,1),
	LocName varchar(255),
	-- other information as required
)
insert into Location values
('Old Factory'),
('New Factory'),
('Outside')
Notice that each location has a Unique identifier and I've allowed SQL to generate that for me.

Next set of obvious duplication is in the bits in brackets. They look to be Supplier names. You might also want to store other information about a supplier, so let's pull them out into a separate table
SQL
create Table Supplier
(
	SupplierId int identity(1,1),
	Supplier varchar(255)
	-- other information e.g. phone number, account manager
)
insert into Supplier values
('CECCATO'),
('Ingersoll Rand'),
('SCM'),
('FIDA'),
('MACMAZZA'),
('SAC'),
('CENTAURO'),
('MASTERWOOD'),
('STROMAB'),
('GABBIANI')
Now I started looking at the Machines themselves - in terms of Products supplied by one of those Suppliers
SQL
create Table Machine
(
	MachId int identity(1,1),	-- Unique Id
	MachineName varchar(255),
	ModelNo varchar(255),
	MadeIn varchar(255),
	Supplier int,	-- this will be a foreign key to the Supplier table
	Category char(2) -- this might be needed from the AC01, CM09 etc
)
-- NOTE - haven't included S.No, Machine Id# , Serial no or Location
-- are these are specific to indivual machines

insert into Machine values
('Air Compressor','CSB 25/10','Italy'	,1, 'AC'),
('Piston Air Compressor',		'462 TV	02'		,'Italy'		,NULL,'AC'),
('Rotary Screw Head Compressor',	'SSR-EP 100'		,'Italy'		,2,'AC'),
('Multi Boring Machine',			'MULTITECH PLUS'	,'Italy'		,3,'BM'),
('Chip Collector',				'SILO'			,'Italy'		,4,'CC'),
('Chip Collector',				'IMPIANTO'		,NULL	,4,'CC'),
('Chip Collector',				'TRC 1001'		,'Italy'		,4,'CC'),
('Chip Collector',				'TRC 711'			,NULL	,4,'CC'),
('Rip Saw',						'SI 450 N'		,'Italy'		,3,'CM'),
('Automatic Panel Sizing Center','TS100'			,'Italy'		,5,'CM'),
('Rip Saw', 						'CS 4'			,'Italy'		,6,'CM'),
('Rip Saw', 						'SI-350 N'		,'Italy'		,3,'CM'),
('Band Saw', 					'R-800'			,'Italy'		,7,'CM'),
('Band Saw', 					'CENTAURO-C'		,'Italy'		,7,'CM'),
('Multi Rip Saw', 				'M-3'				,'Italy'		,3,'CM'),
('Multi Rip Saw', 				'M-2'				,'Italy'		,3,'CM'),
('Chain Cutter', 				'OMR 350'			,'Italy'		,8,'CM'),
('Under Side Cross Cut Saw', 	'RS-110'			,'Italy'		,9,'CM'),
('Double side Cutter', 			NULL			,'Italy'		,10,'CM')
Notice that last column Category If you look at your original data, the non-unique Machine Id # seems to follow a pattern, and that pattern appears to be linked to the Machine Type - so it's worth capturing in case we need to start generating asset numbers later.

Note also that I didn't bother pulling the "Made In" column out - it's something you might like to consider if your actual data has more than one country listed

We've just about got everything now, except for the machines your company owns:
SQL
Create Table AssetRegister
(
	UniqueId int identity(1,1),		-- UNIQUE identifier
	SNo int,				-- From your data - allows duplicates
	MachineId varchar(4),			-- From your data - allows duplicates
	MachId int,				-- will be foreign key to Machine table
	SerialNo	varchar(255),		-- Unique to an individual machine
	Location int				-- will be foreign key to Location table
)

insert into AssetRegister values
(01,	'AC01'	,1,		'CAI 136509'			,1),			
(02,	'AC02'	,1,		'CAI 136510'			,1),			
(03,	'AC03'	,2,		'H1029PKZ'			,1),			
(04,	'AC04'	,3,		'CK 8225U08163'		,2),			
(05,	'BM05'	,4,		NULL				,2),			
(06,	'CC01'	,5,		'SCF 165/04'			,1),			
(06,	'CC01'	,6,		'F 1013/04'			,NULL),		
(07,	'CC02'	,7,		NULL				,2),			
(07,	'CC02'	,8,		NULL				,NULL),		
(08,	'CM02'	,9,		'AB/167284'			,1),			
(09,	'CM04'	,10,	'589'					,1),			
(10,	'CM06'	,11,	NULL				,1),			
(11,	'CM07'	,12,	'AB/153028'			,1),			
(12,	'CM08'	,13,	'6080'				,1),			
(13,	'CM09'	,14,	NULL				,1),			
(14,	'CM10'	,15,	'AB/167282'			,1),			
(15,	'CM11'	,16,	'AB.42150'			,1),			
(16,	'CM12'	,17,	'35109102'			,1),			
(17,	'CM13'	,18,	'91002'				,3),			
(18,	'CM14'	,19,	NULL				,1)
Notice that I've recorded S.No and Machine Id #but I've also assigned each machine it's own unique identifier - this is what I would put the primary key on.

I then ran a query to make sure I could reconstruct your original data:
SQL
SELECT AR.SNo, AR.MachineId,
M.MachineName + ISNULL(' (' + S.Supplier + ')',''),
M.ModelNo, ISNULL(AR.SerialNo, 'Not Available'),
ISNULL(M.MadeIn,'Unknown'), ISNULL(L.LocName,'Not Available')
FROM AssetRegister AR
INNER JOIN Machine M ON AR.MachId = M.MachId
LEFT OUTER JOIN Supplier S ON M.Supplier = S.SupplierId
LEFT OUTER JOIN Location L ON AR.Location = L.LocId


Some more words on the "how" I did all this.
I actually often use Excel with things like this. I can write macros, formulas or just use Edit,Replace to manipulate the data into the table structure - I can then generate the SQL in the spreadsheet or use a bulk import.

Other methods I've used are to load all of the data into a working table, which I then examine and manipulate. E.g to populate the Location table
Insert into Location select distinct Location from work
And then update your working table
SQL
UPDATE W SET Location=LocId
FROM Work W
INNER JOIN Location L on W.Location=L.LocName
UPDATE Work SET Location=NULL WHERE Location='Not Available'
Keep these in a script so that you can re-run it and build the script up in stages.

Once you've got all that in place then consider setting up the foreign keys properly, adding any indexes, etc.

Might not be the ideal solution but should get you started.
GeneralRe: How to make database for a Project Pin
Eddy Vluggen15-Jun-15 10:23
professionalEddy Vluggen15-Jun-15 10:23 
GeneralRe: How to make database for a Project Pin
CHill6015-Jun-15 11:59
mveCHill6015-Jun-15 11:59 
GeneralRe: How to make database for a Project Pin
Eddy Vluggen15-Jun-15 12:20
professionalEddy Vluggen15-Jun-15 12:20 
GeneralRe: How to make database for a Project Pin
Member 1154201015-Jun-15 19:36
Member 1154201015-Jun-15 19:36 
GeneralRe: How to make database for a Project Pin
CHill6015-Jun-15 22:33
mveCHill6015-Jun-15 22:33 
QuestionA C# Windows Application can not run in Windows XP Pin
Member 1173519614-Jun-15 19:06
Member 1173519614-Jun-15 19:06 
AnswerRe: A C# Windows Application can not run in Windows XP Pin
Jim Meadors14-Jun-15 19:14
Jim Meadors14-Jun-15 19:14 
GeneralRe: A C# Windows Application can not run in Windows XP Pin
Member 1173519614-Jun-15 20:51
Member 1173519614-Jun-15 20:51 
GeneralRe: A C# Windows Application can not run in Windows XP Pin
Simon_Whale14-Jun-15 23:07
Simon_Whale14-Jun-15 23:07 
AnswerRe: A C# Windows Application can not run in Windows XP Pin
Bernhard Hiller14-Jun-15 21:47
Bernhard Hiller14-Jun-15 21:47 
SuggestionRe: A C# Windows Application can not run in Windows XP Pin
Richard Deeming15-Jun-15 1:13
mveRichard Deeming15-Jun-15 1:13 
QuestionCard reader and control data Pin
Jean-Pierre Carvalho (JPCarvalho)14-Jun-15 0:51
Jean-Pierre Carvalho (JPCarvalho)14-Jun-15 0:51 
AnswerRe: Card reader and control data PinPopular
OriginalGriff14-Jun-15 1:20
mveOriginalGriff14-Jun-15 1:20 
GeneralRe: Card reader and control data Pin
Jean-Pierre Carvalho (JPCarvalho)14-Jun-15 4:43
Jean-Pierre Carvalho (JPCarvalho)14-Jun-15 4:43 
QuestionBarcode printing Sato Lm 408e thermal SBPL Pin
gunturlin12-Jun-15 2:00
gunturlin12-Jun-15 2:00 
AnswerRe: Barcode printing Sato Lm 408e thermal SBPL Pin
OriginalGriff12-Jun-15 2:41
mveOriginalGriff12-Jun-15 2:41 
QuestionBinaryFormatter - Serialize OutOfMemory Exception Pin
Kit Fisto11-Jun-15 1:54
Kit Fisto11-Jun-15 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.