Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does any one knows how to calculate CRC16 CCTI/False in Sql Server

What I have tried:

I have tried over internet but did not find any solution to CRC16
Posted
Updated 24-Mar-23 20:51pm

1 solution

It can be done, but ... why would you want to?

CRC is a data validation function: it allows your code to check if information is uncorrupted and that is a presentation function - all data should be validated and correct before it gets added to a DB, and checked again for validity when necessary after retrieval by presentation code.

What is the DB engine supposed to do with the CRC - if it generates it on data it receives and stores them both then it's lost a layer of "validity" - the data could be corrupted by the time it arrives at the engine.
If it generates it as a validity check on the way out, then it's validating the stored data which is meaningless given that the transfer already has a couple of layers which include error detection and correction mechanisms.

I've never heard of anyone wanting to do this before, but it is possible (and easier if you have SLQ 22 or higher): Bitwise operators (Transact-SQL) - SQL Server | Microsoft Learn[^] and Function to Calculate a CRC16 Checksum[^] - see Antonio Pires solution. These are in C, not SQL - but you must have a pretty good knowledge of SQL function coding or you wouldn't be asking the question, so it shouldn't be difficult for you to convert and test.

Would I do it? No, not unless there was a compelling reason I couldn't avoid!
 
Share this answer
 
Comments
Member 10664091 25-Mar-23 2:52am    
I want to generate 4 digit hexa code to be used for QR Code in report
OriginalGriff 25-Mar-23 3:01am    
That's a presentation function - do it in your presentation language where it will be both easier and more sensible. SQL is a DB and that' is what it is good at: storing, retrieving, and querying data - not generating it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900