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 2005 Forums
 Transact-SQL (2005)
 Function to concat records

Author  Topic 

TimothyJ
Starting Member

2 Posts

Posted - 2007-08-14 : 09:30:53
Hello there,
I'm designing a database of office equipment at my workplace. Basically I have a table of 'Machines' that have an ID, a username associated with it, a CPU-ID and a couple of other bits of information.

Previously I had a column for a Monitor-ID, where the ID corelated to an entry in a Monitor table. It seemed like the right thing to do, until some people started getting two monitors.

What I've done now instead is have a MonitorsInstalled table. There's a primary key which isn't really used for anything but being unique. Then there's a MachineID and a MonitorID column. The next thing is there can be two entries with the same Machine ID, fixing the whole multiple monitor issue.

However, I have a View setup. Previously the View just listed the monitor name. Now what I'd like to do is concatonate all the monitors associated with one machine and place it into its own column.

So say Machine 321 has a HP1702 and a HPL1940T, and machine 654 has only a HP1702, the view would look like

MachineID Monitor
321 HP1702 & HPL1940T
654 HP1702


Is it possible to do this in a function or stored procedure? If it is, could anyone give me some tips? I'd really appreciated it.

Thanks!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-14 : 09:46:06
If you use front end application, you can easily concatenate there

Otherwise refer
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-14 : 09:51:22
you can do it inline with xml:
http://weblogs.sqlteam.com/mladenp/archive/2007/06/01/60220.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

TimothyJ
Starting Member

2 Posts

Posted - 2007-08-14 : 11:27:00
That worked wonders, thank you :)
Go to Top of Page
   

- Advertisement -