Anyone explain what is happening in the following code? Even an article somewhere that explains why this is happening?
Basically, I have a list of courses offered at my company. The system allows ANY characters to be inserted into the CourseCode value. Somehow we have been getting some non-standard ASCII characters into our database. Our current CourseCode consists of 2 characters, 4 numbers and an optional X character, all terminated by a semi-colon.
The company wants to allow the optional X character to be any alpha character instead. Seems simple enough as I just need to change my LIKE clause to handle the new convention.
But when I do, I introduce the ability pick up non-standard characters, such as Â. I demonstrate a work around below, but I am trying to understand why the A-Z does not work as expected and determine if I need to go back and adjust some other places to make sure I am using the LIKE properly in all my code...
Just trying to understand why this is happening. Thanks.
=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)
Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Senior Database Developer
Basically, I have a list of courses offered at my company. The system allows ANY characters to be inserted into the CourseCode value. Somehow we have been getting some non-standard ASCII characters into our database. Our current CourseCode consists of 2 characters, 4 numbers and an optional X character, all terminated by a semi-colon.
The company wants to allow the optional X character to be any alpha character instead. Seems simple enough as I just need to change my LIKE clause to handle the new convention.
But when I do, I introduce the ability pick up non-standard characters, such as Â. I demonstrate a work around below, but I am trying to understand why the A-Z does not work as expected and determine if I need to go back and adjust some other places to make sure I am using the LIKE properly in all my code...
Just trying to understand why this is happening. Thanks.
Code:
DECLARE @Codes TABLE
(
CourseCode VARCHAR(500)
);
INSERT INTO @Codes (CourseCode) VALUES ('RX1010Â Pharmacy Technician Fundamentals & Computer Applications - Master');
INSERT INTO @Codes (CourseCode) VALUES ('BC1020: Medical Basics and the Healthcare Claim Cycle (1-25-2016) Section 04');
INSERT INTO @Codes (CourseCode) VALUES ('HM2030: Practice Structure and Enhancement (1-25-2016) Section 02');
INSERT INTO @Codes (CourseCode) VALUES ('ME1115X: Introduction to Medical Administrative Assisting (1-04-2016) Section 03');
INSERT INTO @Codes (CourseCode) VALUES ('AC2760Â Accounting for Managers - TRAINING');
INSERT INTO @Codes (CourseCode) VALUES ('PS1000: Psychology (1-04-2016) Section 01');
INSERT INTO @Codes (CourseCode) VALUES ('PS1000X: Psychology (1-04-2016) Section 02');
INSERT INTO @Codes (CourseCode) VALUES ('PS1000C: Psychology (1-04-2016) Section 03');
--All Courses
SELECT
co.CourseCode
FROM @Codes co;
--Current Courses Returned
SELECT
co.CourseCode
FROM @Codes co
WHERE co.CourseCode LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][X:]%';
--Proposed Change
SELECT
co.CourseCode
FROM @Codes co
WHERE co.CourseCode LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][A-Z:]%';
--Expected Change
SELECT
co.CourseCode
FROM @Codes co
WHERE co.CourseCode LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][ABCDEFGHIJKLMNOPQRSTUVWXYZ:]%';
=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)
Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Senior Database Developer