T-SQL Function to Get Int From Varchar(codeforeternity.com)
submitted by
xtremebiz(575) 4 years ago
I recently had to write a T-SQL function which cleans up all non numeric characters from a varchar variable and returns the int value of the remaining numeric characters. If no numeric characters exist, the function should return zero. I thought it would be nice to share this with you and I hope you find this useful ;-) Expected output of the function:
PRINT dbo.GetIntFromVarchar('R1A2J3') -- returns 123
PRINT dbo.GetIntFromVarchar('COOL456CODER') -- returns 456
PRINT dbo.GetIntFromVarchar('789') -- returns 789
PRINT dbo.GetIntFromVarchar('GEEK') -- returns 0
|category: Database
|Views: 43
tags:
Database another
Everyones tags:
Your Tags: