Efficient ISNUMERIC() replacements on SQL Server?

后端 未结 11 2074
失恋的感觉
失恋的感觉 2020-11-27 06:02

So I just spent 5 hours troubleshooting a problem which turned out to be due not only to the old unreliable ISNUMERIC but it looks like my problem only appears

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 06:41

    Another option might be to write an extended stored procedure in a language such as C, make it into a DLL and make it available to SQL Server.

    I don't imagine it would take too many lines of code to do, and it probably would be faster than writing a Managed Stored Procedure in .NET, because you wouldn't incur the extra overheard from loading the CLR.

    Here's a tidbit of information: http://msdn.microsoft.com/en-us/library/ms175200.aspx

    Here's some C++ code that might work for you:

    using namespace std;
    
    int checkNumber() {
      int number = 0;
      cin >> number;
      cin.ignore(numeric_limits::max(), '\n');
    
      if (!cin || cin.gcount() != 1)
        cout << "Not a number.";
      else
        cout << "Your entered: " << number;
      return 0;
    }
    

提交回复
热议问题