Created
November 25, 2013 14:06
-
-
Save lsauer/7641698 to your computer and use it in GitHub Desktop.
T-SQL: Error converting data type varchar to numeric; Procedure workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lsauer.com, 2013 | |
* DECIMAL fields, declared as NOT NULL, cannot be filled by a simple empty string '' | |
* Insert '0.0' or '.0' instead | |
*/ | |
CREATE PROCEDURE GetType(@TableName VARCHAR(100), @FieldName VARCHAR(100)) | |
AS (SELECT system_type_id FROM sys.columns | |
WHERE object_id = OBJECT_ID(@TableName, 'U') AND name = @FieldName) | |
GO | |
EXECUTE GetType N'MyTable', N'MyTableField' | |
/*For instance: 106 is DECIMAL*/ | |
/*Delete when no longer needed*/ | |
DROP PROCEDURE GetType GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment