Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Newbie to SQl, trying to combine multiple tables

Author  Topic 

Newwavedude
Starting Member

1 Post

Posted - 2002-09-18 : 18:29:15
Hi there,

I'm a relative newcomer to SQL, got thrown into a project, based on my programming background, but for the life of me can't figure out how to do a couple of things in SQL.

The first question I have is

We have a table that contains basic incident information( I work for a Fire Department) and one of the fields in that table - Action Taken ID can have multiple values for an incident. My question is - how can I take all the of values and place them into one column/field. I've been messing around with a cursor to do this - but I only get the last value of action taken into the column.


My second question is this

We are creating a text file to be sent to the state for information regarding Fire incidents we respond too. This file contains different types of records that will be linked by the incident. They want a flat file, where the different columns will contain different types of data depending upon the type of record it is. Each record contains a unique record id that the state will use to decipher and determine the record layout for that record. What would be the best way to approach this in SQL? Using a cursor? Again, Im new to SQL so I don't really know many of the techniques used.


Thanks in advance for any help you can offer.

Thomas

chadmat
The Chadinator

1974 Posts

Posted - 2002-09-18 : 18:49:02
Hi,

You need to look into what is called 'Normalization'. You have a Many-to-Many relationship between Incident and Action. One incident can have many actions, and one action can apply to many incidents. So what happens in this situaltion, is each is broken into it's seperate table. You should have an Action table and an Incident table. Then you will have a third table that represents the relationship between the 2.

Ex.

Incidents:
IncidentID | Incident Desc.
1 | Fire at 123 Main St.
2 | Cat in tree


Actions:
ActionID | Action Desc.
1 | Sprayed with water
2 | Drove the fire engine
3 | Climbed Ladder


RelationshipTable (You might call it IncidentAction):
IncidentID | ActionID
1 | 1
1 | 2
2 | 2
2 | 3


So if you joined these tables through the relationship, you will see that for the fire, you drove the Engine, and sprayed with water. And for the cat, you drove the engine, and climbed the ladder.


For the second question, DTS is likely the best solution.

HTH
-Chad



Go to Top of Page
   

- Advertisement -