Book a Demo

Author Topic: SQL query for not equal Stereotype  (Read 5384 times)

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
SQL query for not equal Stereotype
« on: March 27, 2020, 10:14:12 pm »
I want to query for all attributes with a stereotype not equal to "abcd". I am using EA 13.5.

This query will find all attributes with stereotype "abcd":
  select *
  from t_attribute a
  where a.Stereotype like 'abcd'


The contrary search is obvious:
  select *
  from t_attribute a
  where a.Stereotype not like 'abcd'


But although there are attributes with an empty stereotype in the EA-project, the query returns no result.

Regards
Dieter

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: SQL query for not equal Stereotype
« Reply #1 on: March 27, 2020, 10:25:57 pm »
I want to query for all attributes with a stereotype not equal to "abcd". I am using EA 13.5.

This query will find all attributes with stereotype "abcd":
  select *
  from t_attribute a
  where a.Stereotype like 'abcd'


The contrary search is obvious:
  select *
  from t_attribute a
  where a.Stereotype not like 'abcd'


But although there are attributes with an empty stereotype in the EA-project, the query returns no result.

Regards
Dieter
Dieter,
The contrary search is NOT obvious:
  select *
  from t_attribute a
  where a.Stereotype not like 'abcd' or a.Stereotype is Null


As a Data Architect, I HATE Nulls...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: SQL query for not equal Stereotype
« Reply #2 on: March 27, 2020, 10:41:03 pm »
What's that you say? Null not the same as empty?

Sir, I am shocked. Shocked!

 ;D
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: SQL query for not equal Stereotype
« Reply #3 on: March 27, 2020, 10:44:28 pm »
Just try adding 
Code: [Select]
or a.Stereotype = ''
q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SQL query for not equal Stereotype
« Reply #4 on: March 27, 2020, 11:03:26 pm »
Just try adding 
Code: [Select]
or a.Stereotype = ''
q.
That's not the same thing and won't help in case of null

For large databases/complex queries it is often better to avoid "or" statements in the where clause because of performance issues.
That can be avoided by using something like

isnull(a.Stereotype,'') <> 'someStereotype' -- works for SQL Server

or

Coalesce(a.Stereotype,'') --might work for other databases

Each database has a bit it's own operator to replace null values with something else.

Geert

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Re: SQL query for not equal Stereotype
« Reply #5 on: March 27, 2020, 11:26:09 pm »
Thanks for the help. Null is working.