If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Like Statement SQL Suery

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-05, 12:10
SillyOne SillyOne is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Cool Like Statement SQL Suery



)))


This is a simple Like statement.. I have this table call tblCallInfo with a couple of fields in it.. like Id, Date, Calls, PaidCalls, etc..

I wrote this query where I can add up the total of each field pertaining to a certain date typed in or selected such as (it's actually longer but cut off most of the field so it won't seem so long here:

SELECT TBLCallInfo.Date, Sum(TBLCallInfo.PaidCalls) AS SumOfPaidCalls, Sum(TBLCallInfo.FreeCalls) AS SumOfFreeCalls
FROM TBLCallInfo
WHERE (((TBLCallInfo.Date)=#1/3/2005#))
GROUP BY TBLCallInfo.Date;

For this query I queried the to a certain date, but I will have a couple of records from one Month... Is there anyway I can query this Select statement with the total of each field instead of from one date but from all date in that month...

I know it can be done with a statement like:

SELECT TBLCallInfo.Date, Sum(TBLCallInfo.PaidCalls) AS SumOfPaidCalls, Sum(TBLCallInfo.FreeCalls) AS SumOfFreeCalls
FROM TBLCallInfo
-----------------------------------------------------
// *WHERE (((TBLCallInfo.Date)=#1/3/2005#))

WHERE (((TBLCallInfo.Date) LIKE '01/%')) or "'01/%"

//* 1/3/2005#))
------------------------------------------------------
GROUP BY TBLCallInfo.Date;


Having trouble with the LIKe statement... any help appreciated.. Thank you.

Zoila
sillyone8004@yahoo.com



Reply With Quote
  #2 (permalink)  
Old 01-19-05, 13:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
The most efficient way to do this would be something like:
Code:
SELECT
   TBLCallInfo.Date  -- drop this line to get one total for month
,  Sum(TBLCallInfo.PaidCalls) AS SumOfPaidCalls
,  Sum(TBLCallInfo.FreeCalls) AS SumOfFreeCalls
   FROM TBLCallInfo
   WHERE '2005-01-01' <= TBLCallInfo.Date
      AND TBLCallInfo.Date < '2005-02-01'
   GROUP BY TBLCallInfo.Date  -- drop this line to get one total for month
-PatP
Reply With Quote
  #3 (permalink)  
Old 01-19-05, 13:47
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

You can also use BETWEEN:
Code:
...
   WHERE TBLCallInfo.Date BETWEEN '2005-01-01' 
                              AND '2005-02-01'
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 01-19-05, 14:20
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Just remember that BETWEEN '2005-01-01' AND '2005-02-01' is equivalent to >= '2005-01-01' AND <= '2005-02-01'. So if you want to exclude 02-01, use BETWEEN '2005-01-01' AND '2005-01-31' .
Reply With Quote
  #5 (permalink)  
Old 01-19-05, 14:35
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by urquel
Just remember that BETWEEN '2005-01-01' AND '2005-02-01' is equivalent to >= '2005-01-01' AND <= '2005-02-01'. So if you want to exclude 02-01, use BETWEEN '2005-01-01' AND '2005-01-31' .
But that can be problematic if there are times in the dates, since most of the last day gets lost. I think that my answer is easier to read, and harder to get fouled up.

-PatP
Reply With Quote
  #6 (permalink)  
Old 01-19-05, 15:27
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool


Quote:
Originally Posted by Pat Phelan
But that can be problematic if there are times in the dates, since most of the last day gets lost. I think that my answer is easier to read, and harder to get fouled up.
-PatP
If there are times involved, the best answer is:

BETWEEN '2005-01-01' AND '2005-02-01'

Because it implies FROM 2005-01-01 00:00:00 TO 2005-02-01 00:00:00

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #7 (permalink)  
Old 01-19-05, 15:44
SillyOne SillyOne is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Thumbs up Thank you for the Replies..

I used the Between Function with a Where clause because the Group by didn't work...

Thanks a bunch...dbforums

Last edited by SillyOne; 01-19-05 at 16:11. Reason: Realizes answer...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On