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 |
|
marileng
Starting Member
28 Posts |
Posted - 2002-06-19 : 01:05:52
|
| The trucking charge is 200, if the vin have the same tripticket thenthe truckingcharge will be charge only to the first vin .my query is this: Select vin,tripticket, truckingcharge=200 ,storagecharges=200 from vehicleInfoVIN TRIPTICKET TRUCKINGCHARGE STORAGECHARGE1 1 200 200.002 1 200 200.003 2 200 200.004 2 200 200.005 2 200 200.00Results should be :VIN TRIPTICKET TRUCKINGCHARGE STORAGECHARGE1 1 200 200.002 1 0 Dis 200.003 2 200 200.004 2 0 200.005 2 0 200.00 |
|
|
JustinBigelow
SQL Gigolo
1157 Posts |
Posted - 2002-06-19 : 01:47:11
|
create table #tripinfo (vin int,tripticket int, truckcharge int default (200),storagecharge int default (200))insert into #tripinfo (vin, tripticket)values (1,1)insert into #tripinfo (vin, tripticket)values (2,1)insert into #tripinfo (vin, tripticket)values (3,2)insert into #tripinfo (vin, tripticket)values (4,2)insert into #tripinfo (vin, tripticket)values (5,2)Tested this, it should work ok...select vin, tripticket, (select truckcharge = case when vin = (select min(vin) from #tripinfo t2 where t2.tripticket = t1.tripticket) then truckcharge else '0' end) truckcharge, storagecharge from #tripinfo t1hth,Justin< /> |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2002-06-19 : 01:53:46
|
Here is another way to skin a cat...Select min(VIN) as Vin, TripTicket, truckingcharge=200 ,storagecharges=200 from vehicleInfo group by Tripunion allSelect Vin, TripTicket, truckingcharge=0 ,storagecharges=200from vehicleInfo where Vin not in (Select min(VIN) as Vin from v group by Trip) I am pretty sure Justin's will be more efficent....DavidM"SQL-3 is an abomination.."Edited by - byrmol on 06/19/2002 01:54:29 |
 |
|
|
marileng
Starting Member
28 Posts |
Posted - 2002-06-19 : 01:55:06
|
| thanks justin just what I needed |
 |
|
|
|
|
|
|
|