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 |
|
matkwan
Starting Member
36 Posts |
Posted - 2002-03-09 : 22:54:24
|
| Hi, is it possible to perform this in 1 SQL statement :A) Select ItemQTY, Date from Table_A where Item = XXXResults:1, 1/1/20022, 2/1/2002B) Select ItemQTY, Date from Table_B where Item = XXXResults:3, 3/1/20024, 4/1/2002C) Select ItemQTY, Date from Table_C where Item = XXXResults:5, 5/1/20026, 6/1/2002Then add all the results and display them order by DateFinal Results:1, 1/1/20022, 2/1/20023, 3/1/20024, 4/1/20025, 5/1/20026, 6/1/2002Please help.ThanksMatthew |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-03-09 : 22:59:12
|
| You can use UNION or UNION ALL to combine each result together into one:Select ItemQTY, Date from Table_A where Item = XXXUNION ALLSelect ItemQTY, Date from Table_B where Item = XXXUNION ALLSelect ItemQTY, Date from Table_C where Item = XXX |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-03-10 : 07:06:47
|
| orselect ItemQTY, Datefrom(select ItemQTY, Date from Table_Aunion allselect ItemQTY, Date from Table_Bunion allselect ItemQTY, Date from Table_C) as awhere Item = XXXorder by DateYou could make the unions into a view - but should probably merge the tables into one.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|