|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Could somebody please explain to me how do we join a table onto itself as that is what I was advised to do but I can't quite get where I want to go.
What I want to do is list values from a table,but those values can be just a quote (what would cost if they decided to go for that option) or those values can represent what was spent and invoiced, what is confusing me is that all of that gets saved in the same table and in same columns, so what was quoted for example for AirFares and what was spent gets saved in the same record but when it is "quoted amount" then ID = 1 but when it is invoiced ID = -1 and that is how we know what was quoted and what was invoiced. But I need to split that one field into two columns one showing AirFareQuoted and one AirFareInvoiced and i have no idea how to achieve this. I hope this makes sense and somebody can help me |
|
#2
|
|||
|
|||
|
Sending the tables would be helpfull...
But I'm guessing it looks something like this: table #test has row_id, order_id, value_type, value where value_type = 1 or -1 and value stores the number or comment. you could now write a query like this: select a.*, b.value from #test a left join #test b on a.order_id = b.order_id and b.value_type=-1 where a.value_type=1 if input #test is this: 1 1 1 apple 2 1 -1 red 3 2 1 lemon 4 3 1 pear the output would be 1 1 1 apple red 3 2 1 lemon null 4 3 1 pear null hope this helps |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Join tables help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|