SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Dying to solve this problem :-( "SINGLE QUOTATION"


Dying to solve this problem :-( "SINGLE QUOTATION"

Author
Message
Ahmed_07
Ahmed_07
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 16
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
imex
imex
SSC-Enthusiastic
SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)SSC-Enthusiastic (101 reputation)

Group: General Forum Members
Points: 101 Visits: 199
Try:

WHERE Title = 'you''re most welcome'



Hope this helps.

http://www.imoveisemexposicao.com.br
Ahmed_07
Ahmed_07
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 16
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
Ahmed_07
Ahmed_07
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 16
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 Smile
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86574 Visits: 41098
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 Smile


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

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Ahmed_07
Ahmed_07
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 16
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 :-)
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26195 Visits: 17539
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Scott D. Jacobson
Scott D. Jacobson
SSChasing Mays
SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)

Group: General Forum Members
Points: 628 Visits: 1017
Obligatory: http://xkcd.com/327/
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86574 Visits: 41098
Scott D. Jacobson (10/8/2012)
Obligatory: http://xkcd.com/327/

+1000 Absolutely agreed!

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Ahmed_07
Ahmed_07
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 16
okey :-) thankx for the advice 'll think doing so
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search