Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created November 25, 2013 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsauer/7641698 to your computer and use it in GitHub Desktop.
Save lsauer/7641698 to your computer and use it in GitHub Desktop.
T-SQL: Error converting data type varchar to numeric; Procedure workaround
/* 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