Link to home
Start Free TrialLog in
Avatar of Slavak
Slavak

asked on

Data fields...

I have 2 tables in database with one-to-many relationship (actually one-to-two). I built crosstab query on the tables.

Now when I want to show the query in DBGrid I have a problem:I cannot define columns.

If I define "crosstab" columns then I get error if query empty (not have these fields).

If I not define the fields I cannot see it after that.

Any idea?  
Avatar of Phoenix_s
Phoenix_s

what database??
There is not Database methology says one to two, but as you said previus One to Many.

this is very simple query

SELECT C.NAME, Ctry.Country
FROM "customer.db" C
   INNER JOIN "Country.db" Ctry
   ON  (C.CountryID = Ctry.CountryID)  
Where XXXXXXX
Avatar of kretzschmar
hi slavak,

> I built crosstab query on the tables.
can you show the query?

meikl
Avatar of Slavak

ASKER

Sorry for reject answer, but question is not built query, question is how to show it.

Database is MS-ACCESS.

Avatar of Slavak

ASKER

Example of database:

Table "Sites" - geographic places

Fields:

SiteID   : Integer
SiteName : String

Table "Cables" - cables connected the sites

Fields:

CableID   : Integer
CableName : String

Table "CableSites" - every cable related to 2 rows in the table

Fields:

CableID : Integer
SiteID  : Integer
Order   : Integer  - need to built crosstab query


Query SQL :

TRANSFORM Min(Sites.SiteName) AS SiteName
SELECT Cables.CableName
FROM (Sites INNER JOIN CableSites ON Sites.SiteID = CableSites.SiteID) INNER JOIN Cables ON CableSites.CableID = Cables.CableID
GROUP BY Cables.CableName
PIVOT CableSites.Order;
hi slavak,

thats easy
(i guess you use the native driver)

drop TStoredProc-Component on your form

select the alias
select the StoredProcName (your crosstab-query)
set active to true

drop a tdatasource on your form
- connect it to the TStoredProc

drop a tdbgrid on your form
- connect it to the tdatasource

ready

meikl
Avatar of Slavak

ASKER

Ok, meikl.

Now add to query some fields that you need, but want NOT see in DBGrid.

Like this, in my example add to all tables Field "StateID" (just means that may be different states).

New SQL:

TRANSFORM Min(Sites.SiteName) AS SiteName
SELECT Cables.StateID, Cables.CableName
FROM (Sites INNER JOIN CableSites ON Sites.SiteID = CableSites.SiteID) INNER JOIN Cables ON CableSites.CableID = Cables.CableID
GROUP BY Cables.StateID, Cables.CableName
PIVOT CableSites.Order;

But I doun't want to see StateID in DBGrid.

I want to say that I need define DBGrid columns, but I cannot know columns number before opening query.
hi slavak,

just doubleclick on the storedproc-comp
(fieldeditor comes up)
rightclick on it
add all fields
adjust the visible-property of the fields, you don't want to see

meikl
Avatar of Slavak

ASKER

yes, that a probled:

When you define fields by fields-editor, after that you can see
only fields you defined.

In crosstab query you cannot know how many fields contains query before you open (execute) it.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial