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 |
|
hanifbarik
Starting Member
9 Posts |
Posted - 2009-01-28 : 13:01:26
|
| Hi All,I need your help to create a query which returns the name of a JOB and the associated COLOUR. I have two tables:JOB tableID NAME COLOURID1 Barclays 12 Apple 23 Natwest 24 AOL 1COLOUR tableALIAS NAMEText1 RedText2 BlueThe JOB table and the COLOUR table are not linked. However, where the COLOURID is 1, the colour is 'Red'. Where the colour is 2, the colour is 'Blue'. In other words:JOB.COLOURID = COLOUR.ALIAS (minus the 'Text' part)I would like a query which returns the JOB.NAME and COLOUR.NAME. For example,JOB.NAME COLOUR.NAMEBarclays RedApple BlueNatwest BlueAOL RedDo I need to use a function (Right function) to cut the 'Text' part from the COLOUR.ALIAS?If any one can help me with the query, I would appreciate it very much. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-28 : 13:04:15
|
you've in hand. why hesitate to try yourself?SELECT j.NAME,c.NAMEFROM JOB jJOIN COLOUR cON RIGHT(c.ALIAS,1)*1=j.COLOURID |
 |
|
|
hanifbarik
Starting Member
9 Posts |
Posted - 2009-01-28 : 13:18:28
|
| Hi visakh16. Thank you very much. This is exactly what I needed. I was using the wrong joins and making it overly complicated. Thanks. |
 |
|
|
|
|
|