Need a script, SDF or UDF for checking the following conditions and make IF Else in a stored procedure SQL Server
-
Hi, I have 3 different types of values that can come, like for example, I00259, T00123, C00456 etc like that, I want to check an if Else statement in my stored procedure that, 1. If a value has 6 characters in length, and starts with I and ends with a number 2. If a value has 6 characters in length, and starts with T and ends with a number and 3. If a value has 6 characters in length, and starts with C and ends with a number I have to write different sections if the conditions satisfy, any help in SQL Server please.
-
Hi, I have 3 different types of values that can come, like for example, I00259, T00123, C00456 etc like that, I want to check an if Else statement in my stored procedure that, 1. If a value has 6 characters in length, and starts with I and ends with a number 2. If a value has 6 characters in length, and starts with T and ends with a number and 3. If a value has 6 characters in length, and starts with C and ends with a number I have to write different sections if the conditions satisfy, any help in SQL Server please.
You can use the SQL Server LEN() Function[^] to check the length of the string, and the SQL Server SUBSTRING() Function[^] to extract the first character.
-
Hi, I have 3 different types of values that can come, like for example, I00259, T00123, C00456 etc like that, I want to check an if Else statement in my stored procedure that, 1. If a value has 6 characters in length, and starts with I and ends with a number 2. If a value has 6 characters in length, and starts with T and ends with a number and 3. If a value has 6 characters in length, and starts with C and ends with a number I have to write different sections if the conditions satisfy, any help in SQL Server please.
-
Hi, I have 3 different types of values that can come, like for example, I00259, T00123, C00456 etc like that, I want to check an if Else statement in my stored procedure that, 1. If a value has 6 characters in length, and starts with I and ends with a number 2. If a value has 6 characters in length, and starts with T and ends with a number and 3. If a value has 6 characters in length, and starts with C and ends with a number I have to write different sections if the conditions satisfy, any help in SQL Server please.
Someone's trying to teach you how to organize things. Here's a way to consider what they want to teach you: Is the first test you make the first character or the length of the string? As proposed in your (homework) question, one is a more efficient option than the other. Another thing your being taught is "how to look up something you've never done before". You need to make sure you can handle the latter, in particular, if you ever really want to learn how to code.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
You can use the SQL Server LEN() Function[^] to check the length of the string, and the SQL Server SUBSTRING() Function[^] to extract the first character.
Thank you Richard
-
Thank you Richard
-
Hi, I have 3 different types of values that can come, like for example, I00259, T00123, C00456 etc like that, I want to check an if Else statement in my stored procedure that, 1. If a value has 6 characters in length, and starts with I and ends with a number 2. If a value has 6 characters in length, and starts with T and ends with a number and 3. If a value has 6 characters in length, and starts with C and ends with a number I have to write different sections if the conditions satisfy, any help in SQL Server please.
It would probably be easiest to test this using
LIKE
: LIKE (Transact-SQL) - SQL Server | Microsoft Docs[^] Eg: "I" followed by five numbers would be:value LIKE 'I[0-9][0-9][0-9][0-9][0-9]'
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer