A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @HP1979 ,
Welcome to Microsoft Q&A!
It could be recommended for you to post the result of #DRIVES table.
According to limited information you provided, you could refer below suggestions:
- Confirm that there are only numbers in the part of SUBSTRING(INFO, 32, 48).
- Change the 'CHAR(13)' to blank(' ') or another symbol based on your requirement.
- Change the CAST to TRY_CAST.
For example, you will face 'Error converting data type varchar to bigint' errors after executing below queries:
select CAST(REPLACE(SUBSTRING('abcdefghijk12 345', 12, 8), CHAR(13), '') AS BIGINT)
select CAST(REPLACE(SUBSTRING('abcdefghijk12 345', 10, 8), ' ', '') AS BIGINT)
Then we will not face any error if we update them as below:
select CAST(REPLACE(SUBSTRING('abcdefghijk12 345', 12, 8), ' ', '') AS BIGINT)
--12345
select TRY_CAST(REPLACE(SUBSTRING('abcdefghijk12 345', 10, 8), ' ', '') AS BIGINT)
--null
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.