Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query to Select data from a single table with mutliple conditions Expand / Collapse
Author
Message
Posted Wednesday, February 27, 2013 3:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 14, 2013 5:41 AM
Points: 8, Visits: 37
Hi,

I have a table with the below column headings.

Business Unit Document ID Document Date Year Period Account Descr Dept Product Project Analysis Code Affiliate Currency Base Amount USD Amount Line Descr Reference Vendor Vendor Name Module Doc Line # AP Distrib Line # Post Status Seq

I need to pull data with the document date, account and dept.

Where the document data would be the previous month,
there would be multiple accounts: for eg: [FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000
and multiple depts as well.

and it do not get the required data.

Could someone please help me.
Post #1424432
Posted Thursday, February 28, 2013 6:23 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 8:47 PM
Points: 316, Visits: 1,483
renato_mech_334 (2/27/2013)
Where the document data would be the previous month,
there would be multiple accounts: for eg: [FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000
and multiple depts as well.


Hi:
Your question is a little difficult to understand, unfortunately.

But, here's a quick observation I'll share -- if the example criteria you've listed is taken from the sql code, then your results won't likely be as intended. From your example, I think you might try the following with parentheses:

(
[FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900
)
or [FTS Yearly Query].Account = 821000

--pete



Post #1425023
Posted Thursday, February 28, 2013 9:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 14, 2013 5:41 AM
Points: 8, Visits: 37
Hi Pete,

Thanks for the reply.

I figured it out by using it in this format.

WHERE ([FTS Yearly Query].Dept = "3310" ) and ( ([FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000) and (Year([FTS Yearly Query].[Document Date])* 12 + DatePart("m", [FTS Yearly Query].[Document Date]) = Year(Date())* 12 + DatePart("m", Date()) - 1)

Regards,
Renato
Post #1425127
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse