473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multi-Select Statement with Multiple Conditions

40 New Member
Helloo all,

in a previouse thread, and with a lot of help, the following table
Expand|Select|Wrap|Line Numbers
  1. ------------------------------- 
  2. Desc | Entity |  Name  | rate | qty 
  3. --------------------------------- 
  4. xxxx    1        Mark    100     1 
  5. xxxx    2        Mark    100     2 
  6. xxxx    1        Joe     100     3 
  7. xxxx    2        Kive    100     4 
  8. xxxx    1        Ben     100     5 
  9. xxxx    1        Ben     100     6 
  10. -----------------------------------
in an sql statement
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum([rate]*[qty]) AS Expr1  
  2. SELECT TEST.name 
  3. FROM TEST  
  4. GROUP BY TEST.name 
  5. ORDER BY TEST.Name DESC   
  6. PIVOT TEST.entity;
to have the following result
Expand|Select|Wrap|Line Numbers
  1. ========================== 
  2. Names   | 1   |   2 
  3. ========================= 
  4. MARK      100     0
  5. KIVE       0     400
  6. JOE       300     0
  7. BEN       1100    0
Now custmization to be performed.
Lets say i have more entities.
What i need to get as result is
Expand|Select|Wrap|Line Numbers
  1. ========================== 
  2. Names   | 1   |   
  3. ========================= 
  4. MARK      100     x
  5. KIVE       0      y
  6. JOE       300     z
  7. BEN       1100    v
Where x , y , z , v are amounts of each guy in all other entities. ie: entities left, other than 1.

Any suggestions
Apr 6 '11 #1

✓ answered by gershwyn

Where x , y , z , v are amounts of each guy in all other entities. ie: entities left, other than 1.

I've read this a couple times, and it's very hard to tell what you're asking. Are you saying that no matter how many entities there are, there should only be two columns: one for entity = 1, and a second for entity >= 2? On the off chance that is what you want, you can achieve it easily enough with your existing query. Just change the last line to:
Expand|Select|Wrap|Line Numbers
  1. PIVOT IIF([Entity] = 1, "1", "2+")
If that is the case though, your sample data does nothing to illustrate it. There are no entities higher than 2, so the results of this query will be the same as your original.

15 3048
Rabbit
12,516 Recognized Expert Moderator MVP
You'll have to do an aggregate query for the other entities and then full outer join the original table filtering for entity 1 on the original table.
Apr 6 '11 #2
Scorp Scorp
40 New Member
Thanks Rabbit but i failed translating your words into SQL ....

I thought multi select will do the job but non.

Can you translate your idea into SQL ?

thnaks in advance
Apr 7 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Please post the SQL string that you tried.
Apr 7 '11 #4
Scorp Scorp
40 New Member
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum([rate]*[qty]) AS Expr1
  2. SELECT TEST.name, (select SUM([rate[*[qty] From Test where   here i couldnt find what to put
  3. FROM TEST
  4. GROUP BY TEST.name
  5. ORDER BY TEST.Name DESC
  6. PIVOT TEST.entity;
I tried to put a condition , where entity <>1 ... but sure didnt work .


I tried to translate how i figure it how, but couldnt get to the right sql statment. also trying to put the conditions in diff places inside the sql, appeared all to be wrong .... cant figure out how to embbed two sqls to get the required results ....

Never thought of join (which u mentioned earlier) .
Apr 7 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
I don't understand why you have a subquery, I didn't mention a subquery in my post. You just need to take your current query and add a where.

Then you create a simple select query selecting only the entity 1.

Finally, you bring it all together with a full outer join.
Apr 7 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Full OUTER JOINs are not available to Jet SQL Rabbit. Are you referring to non-joined tables (Cartesian Product), where the input sources are listed without JOINs (See SQL JOINs for clarification of terms)?
Apr 7 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
If jet SQL doesn't have full outer join, then yes, they will have to use a cross join with the join information in the where clause.
Apr 8 '11 #8
Scorp Scorp
40 New Member
Rabbit and Neopa , to me now you seem from Mars guys , am not that goooood in Databases , or at least up to that level to know wat you guys talking about ...

Didnt get it, and couldnt solve it ... butt thanks for your effort guys ... thanks.

Thanks for the article Neopa , got an idea on join , but unfortunately couldt relate it to my example here to come up with the prorper solution.

regards,
Apr 10 '11 #9
NeoPa
32,556 Recognized Expert Moderator MVP
I never could work out what the question meant, so I just posted what I knew about when the concept of OUTER JOINs came up. Sorry I couldn't be more help.
Apr 10 '11 #10
Rabbit
12,516 Recognized Expert Moderator MVP
First of all, when I said you need to put a where/having clause in your aggregate query, I don't know how you came up with this.
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum([rate]*[qty]) AS Expr1 
  2. SELECT TEST.name, (select SUM([rate[*[qty] From Test where   here i couldnt find what to put 
  3. FROM TEST 
  4. GROUP BY TEST.name 
  5. ORDER BY TEST.Name DESC 
  6. PIVOT TEST.entity;
What you need is this.
Expand|Select|Wrap|Line Numbers
  1. SELECT TEST.name, Sum([rate]*[qty]) AS Expr1 
  2. FROM TEST
  3. WHERE TEST.entity <> 1 
  4. GROUP BY TEST.name 
  5. ORDER BY TEST.Name DESC;
Then you just need to use a select query to select the records with entity 1 and full outer join (or its equivalent in Jet SQL syntax) the results.
Apr 12 '11 #11
Scorp Scorp
40 New Member
Dear Rabbit ,

What you are providing here is not what i need .

By trial and error i managed find out what u have given me above .

also i know how to get the records for certain entity .

But this makes them 2 seperate queries ,i.e: two seperate sql statements .

Then you just need to use a select query to select the records with entity 1 and full outer join (or its equivalent in Jet SQL syntax) the results.

This is my problem .... what you are saying in english letters , i canot turn it to SQL alphabets ... i.e: in one single sql statment that i can set it in my report.

Thankss any way
Apr 13 '11 #12
Rabbit
12,516 Recognized Expert Moderator MVP
If what I posted isn't what you need, then I don't know what it is you're looking for.
Apr 13 '11 #13
gershwyn
122 New Member
Where x , y , z , v are amounts of each guy in all other entities. ie: entities left, other than 1.

I've read this a couple times, and it's very hard to tell what you're asking. Are you saying that no matter how many entities there are, there should only be two columns: one for entity = 1, and a second for entity >= 2? On the off chance that is what you want, you can achieve it easily enough with your existing query. Just change the last line to:
Expand|Select|Wrap|Line Numbers
  1. PIVOT IIF([Entity] = 1, "1", "2+")
If that is the case though, your sample data does nothing to illustrate it. There are no entities higher than 2, so the results of this query will be the same as your original.
Apr 13 '11 #14
Scorp Scorp
40 New Member
@Rabbit, thanks for following up with me in this thread, and sorry if i couldnt address what i neeed properly ...

@gershwyn

what i have said
Where x , y , z , v are amounts of each guy in all other entities. ie: entities left, other than 1.

is exactly what i meant , my posted example is just a sample. I have more than one entity, but i posted it by mentioning just entity 1 and entity 2 just for breifing.

Your last line
Expand|Select|Wrap|Line Numbers
  1.  PIVOT IIF([Entity] = 1, "1", "2+") 
Is just what i need, will get the sum of entity=1 in one colomn, and sum of all other entities in a second colomn no matter what the entity value...

Worked great ...

Awsome :)

thanks a lot guys

Thanks gershwyn ...
Apr 14 '11 #15
NeoPa
32,556 Recognized Expert Moderator MVP
Scorp scorp, first let me say that I'm happy that Gershwyn's solution resolved the issue for you.

I would like to explain though, that examples are not the whole question certainly, and it is always better if the question is expressed clearly in words without the need for one. Obviously, that's not always easy, for many and various reasons. Because of that, it's important to consider what you post as an example, otherwise you are likely to convince people (as in this case) that you want something quite different from what you actually do. Examples (where used/needed) can be very important parts of the question.

I hope with that understanding you will have an easier time of getting answers to your questions in future :-)
Apr 14 '11 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Greg Bryant | last post by:
Hi folks. I'm porting a cf site to php, everything's going very well, I like php much better (this, of course, being the correct forum to make that statement :). One problem I have is with...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
3
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
1
by: Work.Smarter.1 | last post by:
How do i subtract the first value from the second value without multiple queries? (query example below) SELECT Sum(tbl_Area_PropLend.Amount) AS Default_FinCharge FROM tbl_Area_PropLend GROUP BY...
2
by: probashi | last post by:
Hi, Using the SqlDataSource/SelectParameters/ControlParameter one can easily bind a Grid View with a list box (or any other controls), pretty cool, but my list box is multi select. My...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.