473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

query help


having a spot of trouble writing this one. if you are so inclined and have a
moment, i'd really appreciate your insight.

i have what amounts to a purchase order type of setup...a descriptive header
associated with line items. i have 3 tables...header, lineitem, and
auxiliary. the auxiliary table holds information like subbordinate
information about lineitems that are "non-standard". each of these tables
has a uniqueId column. the lineitem and auxiliary tables have a
parentUniqueId column as well. there is always at least one lineitem whos
parentUniqueId references a header's uniqueId. there are time though, when a
lineitem will reference another lineitem's UniqueId. supplimental data in
the auxiliary table references lineitems in the same fashion except there is
no reflexive self-joining. i know a picture is worth a thousand words, but i
think this is pretty straight-forward.

the data in these tables is sent in xml format via web services to another
server that uses a completely different platform. the web service sends the
status of each record back in xml format confirming which headers,
lineitems, and auxiliary items (by uniqueId) were successfully transfered
and/or which failed. the query i have been trying to write should simply
return the data from all 3 tables as one consolidated record set filtered
such that all related records are returned as long as neither a given,
related header or lineitem or auxiliary where confirmed as failed.

the meat of what i have now is something like:

select items.* ,
a.uniqueId auxId
from
(
select h.uniqueId poId ,
l.uniqueId lineId
from lineItems l
join header h
on h.uniqueId = l.parentUniqueId
union
select h.uniqueId poId ,
child.uniqueId lineId
from lineItems child
join lineItems parent
on child.parentUniqueId = parent.uniqueId
join header h
on h.uniqueId = parent.parentUniqueId
) items
left join auxiliary a
on a.parentUniqueId = items.lineId

this generates the correct view of *all* the data. i need help with the
criterion so that if any related item's uniqueId was said to be "defunct"
then NONE of the other related items should return in the recordset.

thanks for your time, thoughts, and advice.

me
Aug 16 '05 #1
14 2182
 (a@b.com) writes:
i have what amounts to a purchase order type of setup...a descriptive
header associated with line items. i have 3 tables...header, lineitem,
and auxiliary. the auxiliary table holds information like subbordinate
information about lineitems that are "non-standard". each of these
tables has a uniqueId column. the lineitem and auxiliary tables have a
parentUniqueId column as well. there is always at least one lineitem
whos parentUniqueId references a header's uniqueId. there are time
though, when a lineitem will reference another lineitem's UniqueId.
supplimental data in the auxiliary table references lineitems in the
same fashion except there is no reflexive self-joining. i know a picture
is worth a thousand words, but i think this is pretty straight-forward.


We can do without the pictures. However, what we are very fond of are:

o CREATE TABLE scripts for the involved tables (preferrably simplified
to cover the essential in the problem)
o Sample statements with INSERT data.
o The desired result given that sample.

There are at least two reasons we like this:

1) By copying-and-pasting the scripts into Query Analyzer, it's easy to
develop a tested solution.
2) It helps to clarify ambiguities in your narrative.

Judging from the problem it appears that there is some status column
somewhere, but I could not find it the text. (Your reluctance to use
the shift key does not really help.) And I wouldn't mind to see an
example how a lineitem can refer to different sort of parent items.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 16 '05 #2

sorry, ejo...

let's not trifle over the tables save that the all tables have a varchar(50)
column called uniqueId. the lineitem and auxiliary tables have an additional
varchar(50) column called parentUniqueId. let's say the header table's data
looks like:

header (uniqueId is fk to lineitem.parentUniqueId):

uniqueId
A

the lineitem table's data looks like:

lineitem (uniqueId is self-joined by parentUniqueId or an fk to auxiliary):

uniqueId parentUniqueId
X A
Y X
Z X

the aux table's data looks like:

auxiliary:

uniqueId parentUniqueId
L Y
M Z

the query from the previous post would return:

poId lineId auxId
A X
A Y L
A Z M

i'm trying to get only those related items where neither poId, lineId, nor
auxId are in a list of supplied values. i.e. if the list was "QRS", then the
above records *should* show. if the list was "L" for example, then none of
the data above should show...since L is either a poId, lineId, or auxId -
which is the actual case here.
Aug 16 '05 #3

"" <a@b.com> wrote in message news:ti*******************@fe07.lga...
sorry, ejo...

let's not trifle over the tables save that the all tables have a varchar(50) column called uniqueId. the lineitem and auxiliary tables have an additional varchar(50) column called parentUniqueId. let's say the header table's data looks like:
Let's not "say the header table's data looks like" anything.

Erland's point about providing a real DDL is that folks here can then
recreate your exact configuration, design queries and test them against your
exact schema, not their best guess of your interpretation.

If you have business reasons (as is often the case) for needing to keep
details of your schema secret, break the DDL down to the bare minimum that
accurate describes the problm you're trying to solve.


header (uniqueId is fk to lineitem.parentUniqueId):

uniqueId
A

the lineitem table's data looks like:

lineitem (uniqueId is self-joined by parentUniqueId or an fk to auxiliary):
uniqueId parentUniqueId
X A
Y X
Z X

the aux table's data looks like:

auxiliary:

uniqueId parentUniqueId
L Y
M Z

the query from the previous post would return:

poId lineId auxId
A X
A Y L
A Z M

i'm trying to get only those related items where neither poId, lineId, nor
auxId are in a list of supplied values. i.e. if the list was "QRS", then the above records *should* show. if the list was "L" for example, then none of
the data above should show...since L is either a poId, lineId, or auxId -
which is the actual case here.

Aug 17 '05 #4

| If you have business reasons (as is often the case) for needing to keep
| details of your schema secret, break the DDL down to the bare minimum that
| accurate describes the problm you're trying to solve.

jesus christ! how much more "bare minimum" does this get:

"all tables have a varchar(50) column called uniqueId. the lineitem and
auxiliary tables have an additional varchar(50) column called
parentUniqueId...i'm trying to get only those related items where neither
poId, lineId, nor auxId are in a list of supplied values."

there is *no* guessing involved. not only have i provided the structure for
each table, their relation to eachother, a sample of what their data looks
like, but i've even written 90% of the goddamn query...i need help with the
criterion! can no one do that?!!
Aug 17 '05 #5
On Wed, 17 Aug 2005 08:07:30 -0500,  wrote:
| If you have business reasons (as is often the case) for needing to keep
| details of your schema secret, break the DDL down to the bare minimum that
| accurate describes the problm you're trying to solve.

jesus christ! how much more "bare minimum" does this get:

"all tables have a varchar(50) column called uniqueId. the lineitem and
auxiliary tables have an additional varchar(50) column called
parentUniqueId...i'm trying to get only those related items where neither
poId, lineId, nor auxId are in a list of supplied values."

there is *no* guessing involved. not only have i provided the structure for
each table, their relation to eachother, a sample of what their data looks
like, but i've even written 90% of the goddamn query...i need help with the
criterion! can no one do that?!!


Hi ,

As Erland already pointed out in his first reply:

"what we are very fond of are:

o CREATE TABLE scripts for the involved tables (preferrably simplified
to cover the essential in the problem)
o Sample statements with INSERT data.
o The desired result given that sample.

There are at least two reasons we like this:

1) By copying-and-pasting the scripts into Query Analyzer, it's easy to
develop a tested solution.
2) It helps to clarify ambiguities in your narrative."

I fully agree with Erland - if you post the requested information, in
the requested form, then I'm quite sure that people can help you. But if
you decline to provide the information in the recommended form, then you
are indeed making it impossible for us to help you.

Some tips for assembling the CREATE TABLE and INSERT statements we need
to help you can be found here: www.aspfaq.com/5006.

And one other suggestion - don't use swear words. Some people are
offended by language like that. And if you are seeking help, offending
those who offer to help for free is generally not a good idea.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Aug 17 '05 #6
 (a@b.com) writes:
jesus christ! how much more "bare minimum" does this get:

"all tables have a varchar(50) column called uniqueId. the lineitem and
auxiliary tables have an additional varchar(50) column called
parentUniqueId...i'm trying to get only those related items where neither
poId, lineId, nor auxId are in a list of supplied values."

there is *no* guessing involved. not only have i provided the structure
for each table, their relation to eachother, a sample of what their data
looks like, but i've even written 90% of the goddamn query...i need help
with the criterion! can no one do that?!!


I read your previous post, but I failed to comprehend:

i'm trying to get only those related items where neither poId, lineId,
nor auxId are in a list of supplied values. i.e. if the list was "QRS",
then the above records *should* show. if the list was "L" for example,
then none of the data above should show...since L is either a poId,
lineId, or auxId - which is the actual case here.

It may be obvious to you, but it is not to me why none of the rows
would be selected when L is in the list.

You may know your business rules and business domain - we don't. And
if you fail to explain me, it's getting difficult to write a query
for you. I mean, you know the business rules, but can still not write
the query.

Anyway, it's all up to you. If you prefer to yell "Jesus Christ",
rather than helping us to help you, please do so.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 17 '05 #7

| Hi ,

hi, hugo.

| "what we are very fond of are:

well aware by now, i assure you.

| I fully agree with Erland - if you post the requested information, in
| the requested form, then I'm quite sure that people can help you. But if
| you decline to provide the information in the recommended form, then you
| are indeed making it impossible for us to help you.

usually, i agree too. it seems though, (some) people here are incapable of
providing assistance if the post is in *any other form*. i have a problem
with that. there was/is no need to jump through the hoops on this one, as
the most "complex" tables had 2 varchar columns...the other, 1. they related
to eachother in a parent/child,one/many fashion. are you telling me that
that is "hard" to grasp?

far, far from impossible...unless your only modus-operandi is
cut-copy-paste. in that case, i give my condolensces to those with
less-than-normal iqs. that may or may not apply to any of the responders in
this thread...i'm just saying, this was WAY to easy but made WAY too
complex...especially for sooo much bitching.

| Some tips for assembling the CREATE TABLE and INSERT statements we need
| to help you can be found here: www.aspfaq.com/5006.

i'm very...let me say, VERY...experienced with plsql, tsql, and ansi
sql...but, thanks for the link just the same.

| And one other suggestion - don't use swear words. Some people are
| offended by language like that. And if you are seeking help, offending
| those who offer to help for free is generally not a good idea.

i use the words i use. those of which it offends can simply foad (more
sarcastically than actually...pun intended ;^) i'll keep that in mind,
however it seems that unless i fill out the *official help request form*
there is no way i'll be getting help anyway.

i appreciate your input and suggestions, hugo. as it is, i've fixed the
query and have moved on to better things.
Aug 17 '05 #8


| I read your previous post, but I failed to comprehend:

| It may be obvious to you, but it is not to me why none of the rows
| would be selected when L is in the list.
|
| You may know your business rules and business domain - we don't. And
| if you fail to explain me, it's getting difficult to write a query
| for you. I mean, you know the business rules, but can still not write
| the query.

understood. i do. and, i have.

| Anyway, it's all up to you. If you prefer to yell "Jesus Christ",
| rather than helping us to help you, please do so.

it is, and i've taken care of it. "jesus christ" was frustration and was not
in leu of me helping you help me. as a matter of fact, in each post i've
tried to get everyone to understand what i was going for...but all i got in
return was essentially, "we can't function till we can cut/copy/paste". the
table structure was NOT the issue at all and is NOT difficult to create on
your own...2 columns at most, for CHRIST'S sake. ;^) oh well, no need making
this casm of "official posting format" and "pragmatism" what you want...i
already understand that for most here (at least in this case), the divide is
substancially wide.

anyway, the query runs fine now.
Aug 17 '05 #9
 (a@b.com) writes:
the table structure was NOT the issue at all and is NOT difficult to
create on your own...2 columns at most,
Had the rest of the problem description been clear enough I would maybe
have done it. Or just posted an untested query. But when you don't provide
tables, don't provide INSERT statements, don't provide sample data, and
your description is not clear enough, then the bar is too high for me
being interested in playing guessing games.

You see, it's not that I'm paid to do this or anything.
anyway, the query runs fine now.


Glad to hear that you got it working.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 17 '05 #10

| > the table structure was NOT the issue at all and is NOT difficult to
| > create on your own...2 columns at most,
|
| Had the rest of the problem description been clear enough I would maybe
| have done it. Or just posted an untested query. But when you don't provide
| tables, don't provide INSERT statements, don't provide sample data, and
| your description is not clear enough, then the bar is too high for me
| being interested in playing guessing games.

now we enter the realm of "horse-shit". i provided a description of the
tables, just not a create table script. not only that, but i also provided
sample data *and* sample output from the query *i* provided - the response i
got to both of these was: "Let's not 'say the header table's data looks
like' anything." in light of those 2 provisions, the bar was fairly low in
my average estimation...but, i'll give you the benefit-of-the-doubt and
assume you just didn't see my second post *or* the response it got.

each time i posted, i tried to clear up what my aim with the query was but
this was *never* addressed - as each respondant could not get over the
"official post format" condundrum/mantra. i would have tried to better
define this if someone/anyone would have even come close to bucking the
mantra...as no one could, i did not say any more than the first 2 posts
allowed.

| You see, it's not that I'm paid to do this or anything.

cry me a river. i'm a "non-paid" contributer to 3 other newsgroups in which,
my technical prowess is appreciated and respected...even moreso when the op
was vague with defining the problem. i do my best to help each one and i
only get pissed - or become less-than-useful - if the question posted
doesn't relate to the context of the ng. i'm pretty flexible when it comes
to cross and multi posting. this is what i had inadvertantly expected of
contributers here. as this was my first visit here, i will know what to
expect in the future in the way of help...should i ever feel like coming
back! (to which everyone is probably saying, "yeah"...that's fine by me!)

| > anyway, the query runs fine now.
|
| Glad to hear that you got it working.

i do appreciate everyone's participation...i just wish it would have been
more fruitful for all involved.

thanks anyway,

me
Aug 17 '05 #11
"" <a@b.com> wrote in news:6o******************@fe05.lga:

it is, and i've taken care of it. "jesus christ" was frustration and
was not in leu of me helping you help me. as a matter of fact, in each
post i've tried to get everyone to understand what i was going
for...but all i got in return was essentially, "we can't function till
we can cut/copy/paste". the table structure was NOT the issue at all
and is NOT difficult to create on your own...2 columns at most, for
CHRIST'S sake. ;^) oh well, no need making this casm of "official
posting format" and "pragmatism" what you want...i already understand
that for most here (at least in this case), the divide is
substancially wide.

In other words, you're a crybaby who wanted free help, and
then bitched when you got what you paid for.
Nice.

Aug 18 '05 #12
 (a@b.com) writes:
now we enter the realm of "horse-shit". i provided a description of the
tables, just not a create table script. not only that, but i also provided
sample data *and* sample output from the query *i* provided -
Yeah, you did. But you still did not manage did to explain the problem.

Believe it or not, when we suggest that you should post CREATE TABLE
and all that, it is to help you. And, to some extent a little test:
how much effort are you prepare to lay down yourself.
| You see, it's not that I'm paid to do this or anything.

cry me a river. i'm a "non-paid" contributer to 3 other newsgroups in
which, my technical prowess is appreciated and respected...


Maybe you are. That does however not mean that people here have any
particular reason to spend their free time to guess what you are up to.

And, of course, the attitude you have shown in no way encourages people
to help you.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 18 '05 #13
Nothing is free. but you do get something free on the internet.
John S.
--------------------------------------------
http://2020ok.com - Free Online Books

Aug 18 '05 #14
Stu
oh, this thread has it all....

Drama, intrigue, and now, commercials!

/grabs popcorn

Aug 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
7
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all...
4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
5
by: elitecodex | last post by:
Hey everyone. I have this query select * from `TableName` where `SomeIDField` 0 I can open a mysql command prompt and execute this command with no issues. However, Im trying to issue the...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.