Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dying to solve this problem :-( "SINGLE QUOTATION" Expand / Collapse
Author
Message
Posted Saturday, October 6, 2012 4:22 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 5, 2012 12:45 AM
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
Post #1369475
Posted Saturday, October 6, 2012 4:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, December 16, 2014 12:46 PM
Points: 44, Visits: 171
Try:

WHERE Title = 'you''re most welcome'

Hope this helps.


http://www.imoveisemexposicao.com.br
Post #1369479
Posted Sunday, October 7, 2012 12:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 5, 2012 12:45 AM
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 ?????
Post #1369500
Posted Sunday, October 7, 2012 2:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 5, 2012 12:45 AM
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 :)
Post #1369507
Posted Sunday, October 7, 2012 8:23 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:23 PM
Points: 35,821, Visits: 32,494
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
"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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1369531
Posted Monday, October 8, 2012 3:12 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 5, 2012 12:45 AM
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
Post #1369679
Posted Monday, October 8, 2012 9:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 12:10 PM
Points: 13,330, Visits: 12,829
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 Moden's 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)
Post #1369887
Posted Monday, October 8, 2012 10:12 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 19, 2014 7:34 PM
Points: 356, Visits: 925
Obligatory: http://xkcd.com/327/
Post #1369928
Posted Monday, October 8, 2012 11:22 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:23 PM
Points: 35,821, Visits: 32,494
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1369967
Posted Tuesday, October 9, 2012 2:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 5, 2012 12:45 AM
Points: 11, Visits: 16
okey thankx for the advice 'll think doing so
Post #1370222
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse