Book a Demo

Author Topic: How to query for an association class  (Read 7689 times)

patfada

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
How to query for an association class
« on: July 05, 2011, 10:05:23 am »
Hi
 does anyone know how to write a model query to get an association class for a given association?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to query for an association class
« Reply #1 on: July 05, 2011, 04:32:58 pm »
If you know the connector id then this:
Code: [Select]
select * from t_object o
where o.pdata4 like '<connector_ID>'

If you want to join the t_object with t_connector then you'll need some type casting magic to make it happen since pdata4 is a text field, and connector_ID is an integer field.
This code works on SQL Server (2008)
Code: [Select]
select * from t_object o
join t_connector c on cast (cast(o.pdata4 as nvarchar(max))as int) = c.connector_id
where o.name like 'AssociationClassName'

Geert

abruckner

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How to query for an association class
« Reply #2 on: July 05, 2011, 07:19:17 pm »
be carefull using the like-statement, as it works on access (= eap) only. on sql server this is a ntext field, and you would have to cast your search term to a text field.

see also: https://blog.lieberlieber.com/2011/07/01/sql-basics-search-in-ntext-columns/

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to query for an association class
« Reply #3 on: July 05, 2011, 07:37:57 pm »
Andy,

I just tested this on SQL Server 2008 and I got a result just fine :-/

My exact query was:
Code: [Select]
select * from t_object o
where o.pdata4 like '2143504841'

Geert

patfada

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: How to query for an association class
« Reply #4 on: July 06, 2011, 10:23:24 am »
Thanks that worked for me :)

abruckner

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How to query for an association class
« Reply #5 on: July 08, 2011, 06:02:13 pm »
Quote
Andy,

I just tested this on SQL Server 2008 and I got a result just fine :-/

Geert

Thanks for the hint. It's kind of strange, as I use the same version of SQL Server, and it works now. Have to investigate why, because a couple of days ago, it definitly didn't.