SQL syntax help
I have some evaluations that are numbered something "A-05-10-0015" and secondary evaluations numbered something like "A-05-10-0015.A" or "A-05-10-0015.B"  Regardless as to which record I am on at the time, the initial evaluation or .A or .B I am wanting to bring back all values in the database that could be different between each record based on the evaluation number being like "A-05-10-0015".  Can anyone help me?  Any help would be appreciated.
September 14th, 2015 1:03pm

I have some evaluations that are numbered something "A-05-10-0015" and secondary evaluations numbered something like "A-05-10-0015.A" or "A-05-10-0015.B"  Regardless as to which record I am on at the time, the initial evaluation or .A or .B I am wanting to bring back all values in the database that could be different between each record based on the evaluation number being like "A-05-10-0015".  Can anyone help me?  Any help would be appreciated.

>> numbered something "A-05-10-0015"

It is looks like string and not numbers. It is probably NVARCHAR/CARCHAR type. the DDL will show us this.

>> Regardless as to which record I am on at the time

Databases usually works on SETs, not record by record. If you post your DML + what result you want to return we could help more.

>> I am wanting to bring back all values in the database that could be different between each record based on the evaluation number being like "A-05-10-0015".

It looks like you need query that use LEFT function or that it use LIKE filter, but until I see the DDL+DML I can not be sure.

Please post DDL+DML,
so we will be able to understand better and we will have the option to reproduce the issue in our environment.

* I mean that we need queries to create the tables + insert some sample data, instead of description of what you have :-)
* In addition please post the result that you expects to get

Thanks.

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 1:21pm

Select ...

FROM ...

WHERE thecolumn Like 'A-05-10-0015%'


  • Marked as answer by mrbill65 9 hours 18 minutes ago
September 14th, 2015 2:09pm

Can you explain why forums rules do not apply to you? Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. 

>> I have some evaluations that are numbered [sic] something "A-05-10-0015" and secondary evaluations numbered [sic] something like "A-05-10-0015.A" or "A-05-10-0015.B"  <<

Those are not numbers; they are names. This is a nominal scale and it needs a regular expression for validation. And where is the DDL and the name of this column? Have you ever read a book on data modeling? 

>> Regardless as to which record [sic] I am on at the time, the initial evaluation or .A or .B I am wanting to bring back all values in the database that could be different between each record [sic] based on the evaluation number being like "A-05-10-0015".  <<

Rows are not records. This is a fundamental concept in RDBMS. Hre is a guess at DDL. '

CREATE TABLE Evaluations
(eval_id CHAR(16) NOT NULL PRIMARY KEY
  CHECK (eval_id 
    LIKE '[A-Z]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9].[AB ]'),
 ..);

SELECT eval_id
  FROM Evaluations
 WHERE ..;


>> Can anyone help me?  Any help would be appreciated. <<

Please learn to help yourself. Forums are not for basic education. 
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 3:42pm

My apologies and thanks for your response. I thought I had added more explanation and an example of my sql query but evidently my copy and paste did not work.  Long story short the following query worked after I added the "- 1" :

 SELECT LEFT(EvaluationNumber, CHARINDEX('.', EvaluationNumber + '.') - 1) AS EvaluationNumber
 FROM   dbo. Evaluations
 WHERE  EvaluationId = '!PrimaryKey!'

September 14th, 2015 5:45pm

My apologies and thanks for your response. I thought I had added more explanation and an example of my sql query but evidently my copy and paste did not work.  Long story short the following query worked after I added the "- 1" :

 SELECT LEFT(EvaluationNumber, CHARINDEX('.', EvaluationNumber + '.') - 1) AS EvaluationNumber
 FROM   dbo. Evaluations
 WHERE  EvaluationId = '!PrimaryKey!'

  • Marked as answer by mrbill65 9 hours 20 minutes ago
  • Unmarked as answer by mrbill65 9 hours 18 minutes ago
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 5:45pm

My apologies and thanks for your response. I thought I had added more explanation and an example of my sql query but evidently my copy and paste did not work.  Long story short the following query worked after I added the "- 1" :

 SELECT LEFT(EvaluationNumber, CHARINDEX('.', EvaluationNumber + '.') - 1) AS EvaluationNumber
 FROM   dbo. Evaluations
 WHERE  EvaluationId = '!PrimaryKey!'

  • Marked as answer by mrbill65 9 hours 19 minutes ago
  • Unmarked as answer by mrbill65 9 hours 19 minutes ago
September 14th, 2015 5:46pm

You are most welcome :-)
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 5:57pm