Book a Demo

Author Topic: SQL Replace  (Read 7063 times)

rudirijk

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
SQL Replace
« on: June 16, 2016, 08:54:12 pm »
HI,

Im am currently writing a few sql searches to validate my model.

For a certain validation I need to check if an attribute with a certain stereotype has a connector that is 'linked to the attribute'

Linking to an attribute can be done with the 'link to element feature'.

I have found that an attribute has an EA_GUID. For example: {7DBF1703-D202-4336-B1C9-B63D7522089A};
When a connector is linked to this attribute, the StyleEx field of the connector contains: LFSP={7DBF1703-D202-4336-B1C9-B63D7522089A}R;

In order to compare these 2, I need to strip the semicolumn of the EA_GUID. After stripping I can use a statement like below to compare:
select t_connector.Connector_ID
from (t_connector inner join t_attribute on t_connector.Start_Object_ID = t_attribute.Object_ID)
where t_attribute.Stereotype = 'Stamtabel'
and t_connector.StyleEx like '%' + t_attribute.ea_guid + '%'

My question is: How can i strip the semicolumn of the ea_guid?


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: SQL Replace
« Reply #1 on: June 17, 2016, 12:41:19 am »
This is not a SQL forum. You better ask this on StackOverflow.

q.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: SQL Replace
« Reply #2 on: June 17, 2016, 09:26:08 pm »
Ahem. What my esteemed colleague meant to say is that EA supports a large number of underlying databases, so in order to help with a SQL query it's good to know what database you're running EA on since the SQL dialects differ.

(If you're in an .EAP file it's an Access database, Access 3.5 or 4.0 depending on your settings; a .feap file is Firebird.)

But on this occasion it's easier than that. The t_attribute.ea_guid column does not contain any semicolons at all. That's an artifact from (most likely) you copying the data from the search results window, in which case EA adds semicolons as column separators. An ea_guid column is present in many tables, and it always contains only the GUID itself and the curly brackets surrounding it.

(All you religious nutters out there, PLEASE let's not get into a discussion on whether the brackets are part of the GUID or not.)

(Nor one on whether it's "brackets" or "braces.")

(Nor indeed one on whether I placed the full stop correctly there.)

I think the problem is that you're in an .EAP file, which is to say an Access database, but you're using what looks like Transact-SQL, which is appropriate for SQL Server but not for Access. More simply, you're using the wrong wildcard character. Try
Code: (SQL) [Select]
select t_connector.Connector_ID
from (t_connector inner join t_attribute on t_connector.Start_Object_ID = t_attribute.Object_ID)
where t_attribute.Stereotype = 'Stamtabel'
and t_connector.StyleEx like '*' + t_attribute.ea_guid + '*'

Note also that it matters whether you are creating a search definition, or using the SQL scratch pad. If you are creating a search definition, you can use the #WC# macro to resolve the situation and make your query more robust, but the scratch pad sends your queries straight through to the database engine so there you need to use the correct syntax for that engine.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: SQL Replace
« Reply #3 on: June 20, 2016, 12:08:17 pm »
(Nor indeed one on whether I placed the full stop correctly there.)

(Or whether it's a period.)