Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 24th, 2003, 07:24 PM
BubbaBelly BubbaBelly is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 BubbaBelly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yet another weird sql statement

Hello,
Ok, I am need of help with a query statement. I am using mssql. I also have tables with fields: YEAR, MONTH, f1, f2, f3... So what happens is a specify a monthly and a yearly range, so i can grab particular months from the specified years. (This statement works fine). The problem is however, I would like to query from multiple tables as a single result. All the tables have the same field names. All I want to be able to do is grab a single column, say 'f1', from multiple tables within the monthly and yearly ranges. This is basically what I have now:

SELECT t1.f1, t2.f1 FROM t1, t2 WHERE YEAR BETWEEN $begin_year AND $end_year AND MONTH BETWEEN $begin_month AND $end_month

however, it tells me that YEAR and MONTH are ambiguous, which they are. So, I specified the YEAR and MONTH columns as t1.YEAR and t1.MONTH. But my results get really screwed up. I only get results for t1. Is there anyway to generically specify, that you want YEAR and MONTH from every table in the query???

So, I'm kinda stuck.
Your help is much appreciated, thanks in advance.
Bubba

Reply With Quote
  #2  
Old June 24th, 2003, 09:56 PM
marcel marcel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Nieuw Vennep ,Netherlands
Posts: 108 marcel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: yet another weird sql statement

I am not sure but il looks obvious to me

<i>SELECT t1.f1, t2.f1 ....</i> would give 2 fields with the same label f1

maybe this works be better

<i>SELECT t1.f1 AS t1_f1, t2.f1 AS t2_f1 ....</i>

Again, not sure....

Reply With Quote
  #3  
Old June 25th, 2003, 05:26 AM
tkarkkainen's Avatar
tkarkkainen tkarkkainen is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: Finland
Posts: 2,326 tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 19449 Folding Title: Novice Folder
Time spent in forums: 6 Days 10 h 53 sec
Reputation Power: 4
RE: yet another weird sql statement

You know, marcel, I thought the same thing. That's the way I'd try to fix it.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > yet another weird sql statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT