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.
Author |
Topic |
demausdauth
Starting Member
17 Posts |
Posted - 2008-04-18 : 15:26:29
|
Using VS2005 hitting SQL 2005 from a VB.Net windows applicationI have 2 tables Policy, ProducerPolicy contains 4 fields Prod1, Prod2, Prod3, Prod4 (among others)Producer contains ProdNumber, Name What I want to do is Select from the Policy table and for each of the Prod1-4 fields I would like to get the Name value from the Producer table and put it in a temp column called PolicyProd1-4So at the end:Policy return 8 columnsIs this even possible? |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-18 : 15:41:23
|
Your problem is just a badly designed databaseselect p.Prod1, PolicyProd1 = pr1.Name,p.Prod2, PolicyProd2 = pr2.Name,p.Prod3, PolicyProd3 = pr3.Name,p.Prod4, PolicyProd4 = pr4.Name,from Policy pjoin Producer pr1on p.Prod1 = pr1.ProdNumberjoin Producer pr2on p.Prod2 = pr2.ProdNumberjoin Producer pr3on p.Prod3 = pr3.ProdNumberjoin Producer pr4on p.Prod4 = pr4.ProdNumberYou would probably want to make all those left joins as I suspect you might not have all 4 products for a policy.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
demausdauth
Starting Member
17 Posts |
Posted - 2008-04-18 : 15:59:03
|
Works beautifully, my example is only a small part of a larger join statement. When I integrated what you posted it works great. Thanks a lot nr !!! |
|
|
|
|
|
|
|