Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
marxeil
Starting Member
4 Posts |
Posted - 2009-01-02 : 09:12:41
|
I'm new here so hello everyone. I have these 2 tables:MESSAGE_ELEMENTS:ELEMENT_PKELEMENT_NAMEMESSAGE_TYPESCHEMA_ELEMENTS:SCHEMAELEMENT_PK (this is FK from ELEMENTS)ELEMENT_SUPPORT_LEVELThe first table stores a list of elements in message types (each message type is made of a list of elements).The second table stores which fields in a message type are valid in a particular schema. What I want is to get a list of elements for a message type and display the support details for a particular schema: I tried something like this:SELECT MESSAGE_ELEMENTS.* FROM MESSAGE_ELEMENTSLEFT JOIN (SELECT SCHEMA_ELEMENTS.*, RESULT.SUPPORT_LEVELFROM SCHEMA_ELEMENTSWHERE SCHEMA_ELEMENTS.SCHEMA_NAME = [schema name] AS RESULT)ON MESSAGE_ELEMENTS.ELEMENT_PK = RESULT.ELEMENT_PKWHERE MESSAGE_ELEMENTS.MESSAGE_TYPE = [message type]I tried all kind of variations on this and always get errors or wrong results.What am I doing wrong?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-02 : 09:19:01
|
| [code]SELECT *FROM MESSAGE_ELEMENTS meLEFT JOIN SCHEMA_ELEMENTS seON se.ELEMENT_PK=me.ELEMENT_PKAND se.SCHEMA=@YourSchema[/code]where @YourSchema is schema passed. |
 |
|
|
marxeil
Starting Member
4 Posts |
Posted - 2009-01-02 : 09:27:56
|
| This won't help for 2 reasons:1. Its missing the message type as a parameter.2. It will not return all the message elements. It will filter the results with the schema name (I tried this before).It has to be a nested select because there are 2 steps required:1. filter the SCHEMA_ELEMENTS according to the required schema.2. Left join ELEMENTS with the result from step 1, while filtering ELEMENTS according to the required message type. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-02 : 09:34:33
|
quote: Originally posted by marxeil This won't help for 2 reasons:1. Its missing the message type as a parameter.2. It will not return all the message elements. It will filter the results with the schema name (I tried this before).It has to be a nested select because there are 2 steps required:1. filter the SCHEMA_ELEMENTS according to the required schema.2. Left join ELEMENTS with the result from step 1, while filtering ELEMENTS according to the required message type.
just change like thisSELECT *FROM MESSAGE_ELEMENTS meLEFT JOIN SCHEMA_ELEMENTS seON se.ELEMENT_PK=me.ELEMENT_PKAND se.SCHEMA=@YourSchemaWHERE me.MESSAGE_TYPE=@messgae_type what you asid about 2 is not true.it will return all message elements and return those associated schema details where schema name is passed on value |
 |
|
|
marxeil
Starting Member
4 Posts |
Posted - 2009-01-02 : 10:15:08
|
| Sorry, it was my mistake.I just noticed that this is SQL server 2005 dedicated forum. I am trying to do this with MS ACCESS.I tried your code in SQL SERVER 2005 and it works perfectly. Access however does not support this syntax.So sorry again and I'll take myself and my question to the right forum. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-02 : 10:20:50
|
quote: Originally posted by marxeil Sorry, it was my mistake.I just noticed that this is SQL server 2005 dedicated forum. I am trying to do this with MS ACCESS.I tried your code in SQL SERVER 2005 and it works perfectly. Access however does not support this syntax.So sorry again and I'll take myself and my question to the right forum.
No problem Unforunately i'm not an Access expert, so please post this in Access forum here. |
 |
|
|
|
|
|