sql - SUBSTRING in a Scalar UDF - Unexpected Return -
I am working in SSMS 2012. I have a scalar UDF that tests to see if a certain value is a 3-digit number: Returning announcement @output varchar (50) set @output = is the case when LEN (@input) &
create function [dbo] [test8] (nvarchar @input) varchar (50) Lt; & Gt; 3 'Failure' when left (@ input, 1) not having 3 characters like '% [123456789]%' --must then 'failure' --first character is a natural number when substring (@ input, 2,1 '% [0123456789]%' then 'Failure' --second character should be a natural number (not including zero) when the string (@ input, 3,1) does not like '% [0123456789]%' Then 'Failure' - The third character should be a natural number (zero inclusive) ELSE 'success' END returns @out put END They have the following questions, in which I am trying to return the record where a fixed column fails when it has passed the UDF:
Select Col1 with some_table where Dbo.test8 (Col2) = 'Failure' I have many records that will give 'success' to this UDF (e.g., '123'), but they are returning to the query whose It means that the UDF is returning 'failure' to them. What's wrong with my query? My best estimate is that there is something to do with SUBSTRINGS.
When one does not specify the size of (n) varchar parameter 1, get the default length of character.
Change
create function [dbo]. [Test8] (nvarchar @input) to
create [dbo]. [Test8] (@input nvarchar (4))
Comments
Post a Comment