June 15, 2022 at 2:50 am
I have table and record as below. I have this database in DB2 and I replicate this databse in SQL server 2016 as well. In DB2, the same exact where clause returns rows, whereas in SQL server, it doesn't return anything. Is this because way SQL server does sorting is different than DB2? What can I do in SQl server to make it return results?
any help would be appreciated.
CREATE TABLE #temp (idaisl VARCHAR(10), basil VARCHAR(10), eaisl VARCHAR(10))
INSERT INTO #temp
SELECT 'V', 'A', '9'
SELECT * FROM #temp
WHERE idaisl BETWEEN basil AND eaisl
June 15, 2022 at 7:57 am
What collation is the DB2 database using?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 15, 2022 at 1:20 pm
Yes you are right EBCDIC and ASCII have different binary value sets. For example, "a" is less than "A" in EBCDIC, but "a" is greater than "A" in ASCII. Numeric characters are less than any alphabetic letter in ASCII but are greater than any letter in EBCDIC.
June 15, 2022 at 1:41 pm
And that leads us to something like this:
SELECT *
FROM #temp
WHERE idaisl COLLATE SQL_EBCDIC037_CP1_CS_AS
BETWEEN basil COLLATE SQL_EBCDIC037_CP1_CS_AS AND eaisl COLLATE SQL_EBCDIC037_CP1_CS_AS;
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 15, 2022 at 1:46 pm
Alternatively, I think modifying the default collation on your database before creating tables and adding data to them should also do the trick (and then you'll be able to write queries without having the COLLATE keyword all over).
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 16, 2022 at 12:29 am
This was a life saver. Thank you very much!
June 16, 2022 at 2:04 pm
This was a life saver. Thank you very much!
Remember TempDB when you do this. If it has a different collation, you might be in for a heap of trouble with "mixed" collations.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply