| Author |
Topic |
|
lauramayer
Posting Yak Master
152 Posts |
Posted - 2005-08-18 : 11:03:58
|
| Morning,I know there is a way to do this but either I have not had enough coffee or I'm losing what's left of my mind.I have 2 views: view A has the syntax select bodytype, facility where blah blahresults: drybox Aberdeen, reefer Aberdeen, special Aberdeenview B has the same syntax select bodytype, facility where blah blahBUT the results here are: All Trailers AberdeenI want to combine the two so I get reefer Aberdeendrybox Aberdeenspecial AberdeenAll Trailers AberdeenI'm going to slap myself when I read the answer. I know it's that simple but the simple things are sometimes the least obvious :)Thanks for any help you can offer.Laura |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-08-18 : 11:23:28
|
| select bodytype, facility FROM ViewA where blah blahUNION ALLselect bodytype, facility FROM ViewB where blah blahI think. If you follow the hint link below, and post like I suggest, we can be sure it's what you want.Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
lauramayer
Posting Yak Master
152 Posts |
Posted - 2005-08-18 : 11:34:49
|
Thanks Brett,UNION is almost it. I didn't post the code becasue its ssooooo long, lots of fields but I'll scale it down and just give the gory details. What I want, needy creature that I am, is b.BodyType and a.bodytype combined into one field. Thanks as alwaysLauraSELECT b.Facility, b.BodyType, a.bodytype, b.UpLoadDate FROM dbo.vwYC8DayAll_1A as b INNER JOINdbo.vwAllTrailers as a ON b.Facility = a.Facility AND b.UpLoadDate = a.UpLoadDate |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
lauramayer
Posting Yak Master
152 Posts |
Posted - 2005-08-18 : 12:33:15
|
| Well that gives me:DryBoxAll TrailersReeferAll TrailersSpecialtyAll Trailers what I NEED is this:reefer Aberdeendrybox Aberdeenspecial AberdeenAll Trailers AberdeenIs it even possible? I'm starting to wonder.... |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
lauramayer
Posting Yak Master
152 Posts |
Posted - 2005-08-18 : 12:57:36
|
Okay using this querySELECT b.Facility, b.BodyType, a.bodytype, b.UpLoadDate FROM dbo.vwYC8DayAll_1A as b INNER JOINdbo.vwAllTrailers as a ON b.Facility = a.Facility AND b.UpLoadDate = a.UpLoadDate Gives me this result set:Facility BodyType bodytype UpLoadDate -------- ------------ ------------------------------ Aberdeen DryBox All Trailers 08/11/2005Aberdeen Reefer All Trailers 08/11/2005Aberdeen Specialty All Trailers 08/11/2005Aberdeen DryBox All Trailers 08/12/2005Aberdeen Reefer All Trailers 08/12/2005Aberdeen Specialty All Trailers 08/12/2005Aberdeen DryBox All Trailers 08/13/2005Aberdeen Reefer All Trailers 08/13/2005Aberdeen Specialty All Trailers 08/13/2005Using the code below:SELECT b.Facility, b.BodyType + a.bodytype AS NewBodyType,b.UpLoadDate FROM dbo.vwYC8DayAll_1A as b INNER JOINdbo.vwAllTrailers as a ON b.Facility = a.Facility AND b.UpLoadDate = a.UpLoadDate I get:Facility NewBodyType UpLoadDate -------- ------------ ---------------------- Aberdeen DryBoxAll Trailers 08/11/2005Aberdeen ReeferAll Trailers 08/11/2005Aberdeen SpecialtyAll Trailers 08/11/2005Aberdeen DryBoxAll Trailers 08/12/2005Aberdeen ReeferAll Trailers 08/12/2005Aberdeen SpecialtyAll Trailers 08/12/2005Aberdeen DryBoxAll Trailers 08/13/2005Aberdeen ReeferAll Trailers 08/13/2005Aberdeen SpecialtyAll Trailers 08/13/2005 What I want is:Facility BodyType UpLoadDate -------- ------------ ------------------------------ Aberdeen DryBox 08/11/2005Aberdeen Reefer 08/11/2005Aberdeen Specialty 08/11/2005Aberdeen AllTrailers 08/11/2005Aberdeen DryBox 08/12/2005Aberdeen Reefer 08/12/2005Aberdeen Specialty 08/12/2005Aberdeen AllTrailers 08/12/2005Aberdeen DryBox 08/13/2005Aberdeen Reefer 08/13/2005Aberdeen Specialty 08/13/2005Aberdeen AllTrailers 08/13/2005Does that make it more clear? Thanks for the helpLaura |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-08-18 : 13:23:47
|
Laura, I was fishing for a format I could just cut and paste so I could figure it out, AND confirm that we are on the same page..This gives your results as you want...but it doesn't make much senseUSE NorthwindGOSET NOCOUNT ONCREATE TABLE vwYC8DayAll_1A_99 (Facility varchar(25), BodyType varchar(25), UpLoadDate datetime)CREATE TABLE vwAllTrailers_99 (BodyType varchar(25), UpLoadDate datetime)GOINSERT INTO vwYC8DayAll_1A_99 (Facility, BodyType, UpLoadDate)SELECT 'Aberdeen', 'Drybox All' , '8/11/2005' UNION ALLSELECT 'Aberdeen', 'Reefer All' , '8/11/2005' UNION ALLSELECT 'Aberdeen', 'Specialty All', '8/11/2005' UNION ALLSELECT 'Aberdeen', 'Drybox All' , '8/12/2005' UNION ALLSELECT 'Aberdeen', 'Reefer All' , '8/12/2005' UNION ALLSELECT 'Aberdeen', 'Specialty All', '8/12/2005' UNION ALLSELECT 'Aberdeen', 'Drybox All' , '8/13/2005' UNION ALLSELECT 'Aberdeen', 'Reefer All' , '8/13/2005' UNION ALLSELECT 'Aberdeen', 'Specialty All', '8/13/2005'INSERT INTO vwAllTrailers_99 (BodyType, UpLoadDate)SELECT 'Trailers' , '8/11/2005' UNION ALLSELECT 'Trailers' , '8/11/2005' UNION ALLSELECT 'Trailers' , '8/11/2005' UNION ALLSELECT 'Trailers' , '8/12/2005' UNION ALLSELECT 'Trailers' , '8/12/2005' UNION ALLSELECT 'Trailers' , '8/12/2005' UNION ALLSELECT 'Trailers' , '8/13/2005' UNION ALLSELECT 'Trailers' , '8/13/2005' UNION ALLSELECT 'Trailers' , '8/13/2005'GO SELECT Facility, BodyType, UpLoadDate FROM vwYC8DayAll_1A_99 UNION ALL SELECT DISTINCT a.Facility, b.BodyType, b.UpLoadDate FROM vwYC8DayAll_1A_99 aINNER JOIN vwAllTrailers_99 b ON a.UpLoadDate = b.UpLoadDate ORDER BY UpLoadDate, BodyTypeGOSET NOCOUNT OFFDROP TABLE vwYC8DayAll_1A_99, vwAllTrailers_99 Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
lauramayer
Posting Yak Master
152 Posts |
Posted - 2005-08-18 : 13:39:02
|
| Thanks Brett. I never know if I'm posting to much. Sometimes people don't read if it seems like there is to much text. You just can't win :)Thanks againLaura |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-08-18 : 13:45:53
|
| Typically a short paragraph explaining what your problem is then the DDL, DML for sample data, and the expected result set is all that we need to get started at least. I agree that long posts might not even be read, but keep in mind that the DDL, DML, and expected result set are needed for us to help you so don't consider this part when thinking about how long the post is.Tara |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|