This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3676|Reply: 0

[Source] SQL Server finds the data that varchar converts to bigint error

[Copy link]
Posted on 8/12/2023 5:19:55 PM | | | |
Requirements: When the SQL Server database executes a query statement, the returned field is of varchar type, which needs to be converted to bigint type, and then an error will be reported if it encounters a string such as a letter.Error converting from data type varchar to bigint.”。

There are two solutions:

1. Find out the error data and fix it
2. With the TRY_CAST function, if the conversion fails, it returns NULL

If you use Solution 1 in this article, the error will be reported as follows, how to find the wrong data?



To find out the error data, you can useTRY_CASTISNUMERICTRY_CONVERTThe function is solved, ISNUMERIC encounters an error and the data returns 0, TRY_CAST, TRY_CONVERT conversion fails to return NULL, as shown in the figure below:




Test script:

(End)





Previous:Resolved the Dapper.Contrib error "Value is too large or too small for Int32"
Next:.NET/C# implements the IEqualityComparer custom comparator
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com