|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
String Manipulation in Query Result
I have the following rows in a table, i have to write a query which returns
results as shown Table Values Result -------------- ---------------- 100 --> 100 100N --> 100N 100NCA ---> 100N(CA) 200J ---> 2000J 2000CA ---> 2000(CA) Logic: Check last two characters of string, if both are alphabets, then add ( ) before and after and return...for anything else just return original How can i write such a query? Thanks in advance |
|
#2
|
||||
|
||||
|
This is a good question. I do know you could print the parenthesis like this, for example:
Code:
declare @city nvarchar(255)
Select @city = city
From table1
Where city = 'Bel Point'
print '(' + @city + ')'
The result would look like this (Bel Point). Of course in your case, you need to check the last two characters. You'd probably use an if statement and somehow extract the last two characters of your variable and check for alphabet values. That I'm not sure how to do but hopefully someone will add this part.
__________________
Keep it Prodigy, Keep it Real |
|
#3
|
|||
|
|||
|
What database?
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > String Manipulation in Query Result |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|