October 6, 2012 at 4:22 pm
it's only about ( SINGLE QUOTATION) in ASP.NET
here is my SQL Query:
SELECT ID, Title
FROM viewTopTitles
WHERE Title = ' you're most welcome '
but duo to the SINGLE QUOTATION I have a fatal Error, I tried to use function like this:
WHERE REPLACE("you're most welcome", " ' ", " ' ' ")
...
Error I get with this is :
Msg 4145, Level 15, State 1, Line 3
An expression of non-boolean type specified in a context where a condition is expected, near ')'.
and thene tried like this :
WHERE Title = REPLACE("you're most welcome", " ' ", " ' ' ")...
Error I get with this is :
Msg 207, Level 16, State 1, Line 3
IS THERE ANY BODY CAN GIVE ME A FULL EX. OF THE QUERY, OR TELLS ME HOW APPROPRIATE SHOULD I'VE TO USE THIS;
THANK YOU
PS: I AM KINDDA NEW TO THIS :ermm:
October 6, 2012 at 4:37 pm
Try:
WHERE Title = 'you''re most welcome'
Hope this helps.
October 7, 2012 at 12:26 am
thanks imex
but it would work in Query Engine in SQL Server but as in my case am in ASP.NET and can't fix with this all the links (Titles) that contain SINGLE QUOTATIONS
so how could I avoid the error dynamically ????? :ermm:
October 7, 2012 at 2:05 am
I found it 🙂
here is the solution
public string mySTRING (string singleQ){
return singleQ.Replace(" ' ", " ' ' ");
}
SELECT ID, Title
FROM viewTopTitles
WHERE Title = mySTRING (you're most welcome)
SOURCE : http://www.sqlfr.com/forum/sujet-PROBLEME-AVEC-APOSTROPHE_1349006.aspx
info : the forum is in French lang but you should see the full code there probably understand 🙂
October 7, 2012 at 8:23 am
Ahmed_07 (10/7/2012)
I found it 🙂here is the solution
public string mySTRING (string singleQ){
return singleQ.Replace(" ' ", " ' ' ");
}
SELECT ID, Title
FROM viewTopTitles
WHERE Title = mySTRING (you're most welcome)
SOURCE : http://www.sqlfr.com/forum/sujet-PROBLEME-AVEC-APOSTROPHE_1349006.aspx
info : the forum is in French lang but you should see the full code there probably understand 🙂
If you run that result query you posted, I'm pretty sure you'll find that it doesn't actually work. The single quote needs to have two single quotes and the whole string literal needs to be wrapped in single quotes.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 8, 2012 at 3:12 am
you're right, it's just that I didn't mentioned or write it in here, but I did wrap it with a single quotation to the whole string 🙂
thank you 🙂
October 8, 2012 at 9:22 am
Or for an even better approach don't use pass through sql from your .NET app. Instead use parameters. From the issues you are facing it is very likely that your application is vulnerable to sql injection.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 8, 2012 at 10:12 am
October 8, 2012 at 11:22 am
+1000 Absolutely agreed!
--Jeff Moden
Change is inevitable... Change for the better is not.
October 9, 2012 at 2:45 am
okey 🙂 thankx for the advice 'll think doing so
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply