?
Solved

SQL qyestion

Posted on 2009-12-23
2
Medium Priority
?
167 Views
Last Modified: 2012-05-08
I have this SQL:

Select acct, acct_unit1, trans_date, ref, voucher, from_id, ref_type, dom_amount  From ledger
WHERE     (trans_date >= '01/01/2009') AND (trans_date <= '12/31/2009')

Which works fine but I have additional criteria that needs to be filtered withen that date-range


AND ((acct = '60500') AND (acct_unit1 >= '3000') AND (acct_unit1 <= '3110'))  OR ((acct >= '61000') AND (acct_unit1 >= '3000') AND (acct_unit1 <= '3110')) OR ((acct >= '61000') AND (acct_unit1 >= '4000') AND (acct_unit1 <= '4100'))
0
Comment
Question by:thenrich
2 Comments
 
LVL 10

Expert Comment

by:lof
ID: 26116458
where is the problem?

for now I suggest using between and slightly different formatting for improved legibility
Select acct, acct_unit1, trans_date, ref, voucher, from_id, ref_type, dom_amount  
From ledger
WHERE  trans_date between '01/01/2009' AND trans_date <= '12/31/2009'
and 
(
	(
		acct in ('60500', '61000') 
		and acct_unit1 between '3000' and '3110'
	)
	or 
	(
		acct >= '61000' 
		and acct_unit1 between '4000' and '4100'
	)
)

Open in new window

0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 26116517
Does this work?

~bp
SELECT acct,
       acct_unit1,
       trans_date,
       REF,
       voucher,
       from_id,
       ref_type,
       dom_amount
  FROM ledger
 WHERE (trans_date BETWEEN '01/01/2009' AND '12/31/2009')
   AND (((acct =  '60500') AND (acct_unit1 BETWEEN '3000' AND '3110'))
    OR  ((acct >= '61000') AND (acct_unit1 BETWEEN '3000' AND '3110'))
    OR  ((acct >= '61000') AND (acct_unit1 BETWEEN '4000' AND '4100')))

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question