SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query to Select data from a single table with mutliple conditions


Query to Select data from a single table with mutliple conditions

Author
Message
renato_mech_334
renato_mech_334
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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.
peterzeke
peterzeke
Say Hey Kid
Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)Say Hey Kid (682 reputation)

Group: General Forum Members
Points: 682 Visits: 1766
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



renato_mech_334
renato_mech_334
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search