Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I work on sql server 2014 i face issue when i need to add double quotes for operator
bigger than as > only
but my issue it applied also on not equal <>
so how to solve issue please

as sample
>10 then it will be >'10'
<>9 will be <>9
with another meaning
when use CHARINDEX('>', EStrat) > 0
apply for column EStrat that have sign > only
and not apply for sign <>
so how to do that please ?

What I have tried:

SQL
CASE 
                         WHEN CHARINDEX('>', EStrat) > 0 THEN REPLACE(EStrat, '>', '>''') + ''''
Posted
Updated 3-Dec-21 20:01pm
v2

1 solution

Basically, you are going about it the wrong way: SQL string handling is very poor and there is no full regex system built into SQL. For that reason, you are much, much better doing this in a presentation language when you add the data to the DB, instead of expecting it to be sorted out in the database later.

Databases are very good as storing, retrieving, and organising data, but they aren't good at manipulating data.
With a regex, it's not difficult, match this:
([^\<]+>)(\d+)
And replace it with this:
$1'$2'

But in SQL strings? It'll be horribly complicated, and difficult to maintain when you realise it should include ">=" as well ...

Do all data manipulation in your presentation language, where things are pretty simple so the DB data is already normalized and consistent!
 
Share this answer
 
Comments
ahmed_sa 4-Dec-21 4:49am    
i need regex on sql server get me > and not get <>
as sample below
create table #temp
(
InsertData nvarchar(50)
)
insert into #temp(InsertData)
values
('>10'),
('<> solid data')

how to return first result on insertdata column value >10
OriginalGriff 4-Dec-21 5:05am    
What part of "and there is no full regex system built into SQL" did you not understand?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900