Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site was well structured and I found what I was looking for in about 2 minutes. I am looking forward to participating with you in the future..."

Geography

Where in the world do Tek-Tips members come from?
Amesville (Programmer)
11 May 12 13:19
Hi Folks

Ran into this problem working on an application I'm writing, not sure how to get around it...

SELECT CatalogID FROM Catalog cat
LEFT JOIN Town tn ON cat.RouteIntOnAt = tn.TownCallSign
WHERE cat.PrintLoadSide1 = 'Y'
AND tn.townStagedArea = @Par1 --Name of Staging area
AND Cat.SessionSelect = ''
AND Cat.CatComm IN (SELECT LrCommodity FROM LoadRestrict WHERE lrTrainType = @Par2)
UNION
SELECT CatalogID FROM Catalog
WHERE PrintLoadSide1 = 'N'
AND RouteVerso <> 'Start at Industry'
and SessionSelect = ''
AND Cat.CatComm IN (SELECT LrCommodity FROM LoadRestrict WHERE lrTrainType = @Par2);

I'm getting an error on the bold part above; apparently it doesn't like me using Cat.CatComm twice. But I'm fairly sure it has something to do with the subquery being repeated. Any suggestions on how I can make this work? Thanks!

Craig
Amesville (Programmer)
11 May 12 13:20
Oh Duh, never mind I just saw my stupid error. Sorry!
OlafDoschke (Programmer)
11 May 12 14:11
Yes, too few cats. Look out for an old lady in your neighborhood, they often have too much of 'em.

Sorry, this was too tempting.

Bye, Olaf.
Helpful Member!  OlafDoschke (Programmer)
11 May 12 14:29
Looking closer at this, you could also put all this in one WHERE without a union anyway, some conditions are valid for both queries, some other can be combined via OR:

CODE

SELECT CatalogID FROM Catalog cat LEFT JOIN Town tn ON cat.RouteIntOnAt = tn.TownCallSign WHERE Cat.SessionSelect = '' AND Cat.CatComm IN (SELECT LrCommodity FROM LoadRestrict WHERE lrTrainType = @Par2) AND ( (cat.PrintLoadSide1 = 'Y' AND tn.townStagedArea = @Par1) OR (cat.PrintLoadSide1 = 'N' AND cat.RouteVerso <> 'Start at Industry') );

Would that work, too?

Bye, Olaf.
Amesville (Programmer)
12 May 12 17:35
Hi Olaf

Yes, I think that will work better... Thanks!

Craig

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close