Click here to Skip to main content
15,798,151 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
there are many special characters like "-","_" etc. in sql i want to remove that characters in select query itself. so is thr any way to do it???
or i have to use update query only???

but if possible plz suggest in select query itself...

tnx in advance..

Try this.
SELECT REPLACE(REPLACE(field_name,'-',''),'_','') from table_name 
Share this answer
Manfred Rudolf Bihy 4-May-11 6:18am    
I remember doing that once! 5+
(Not proud of if, but it was the easiest way to go.)
Toniyo Jackson 4-May-11 6:20am    
Thanks. I didn't find any other way.
use the solution one from the below link

Select number part from a value[^]

After little tweak you can do in the select statement
Share this answer
You've too use a replace function.

This pieco of code shows how you can do that.

p = p.Replace("  ", string.Empty);
p = p.Replace(Environment.NewLine, string.Empty);
p = p.Replace("\\t", string.Empty);
p = p.Replace(" {", "{");
p = p.Replace(" :", ":");
p = p.Replace(": ", ":");
p = p.Replace(", ", ",");
p = p.Replace("; ", ";");
p = p.Replace(";}", "}");
return p;
Share this answer
Don't. Use parametrized queries instead:
using (SqlConnection con = new SqlConnection(strConnect))
    using (SqlCommand com = new SqlCommand("SELECT iD, description FROM PurchaseTypes WHERE name=@NM", con))
        com.Parameters.AddWithValue("@NM", myTextBoxWithHisNameInIt.Text);
        using (SqlDataReader reader = com.ExecuteReader())
            while (reader.Read())
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
Share this answer

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