Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / March 2007

Tip: Looking for answers? Try searching our database.

A QuotedStr function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Willo - 28 Mar 2007 18:44 GMT
Hi;

is there a function to add quotes to a string sentence?; like this

exec('Select * from Customers where Name='+@NAMEC+' and AGECUST > 25')

if @NAME is only William, i need to add quotes to it to get a sentence like:

Select * from Customers where Name='William' and AGECUST > 25

is there a function to do that?
Amarnath - 29 Mar 2007 12:24 GMT
There is no special function for that. you can do in 2 ways.
1. use double quotes and set quote identifier off so that you can use both
double and single quotes.
2. for using single quote in your string you need to put one more single
quote.
ie taking your e.g

exec('Select * from Customers where Name= '' '+@NAMEC+ ' '' and AGECUST > 25')
please note it looks like double quote it is not, it is 2 single quotes.

Try this.

Amarnath, MCTS

> Hi;
>
[quoted text clipped - 7 lines]
>
> is there a function to do that?
Willo - 29 Mar 2007 15:50 GMT
> There is no special function for that. you can do in 2 ways.
> 1. use double quotes and set quote identifier off so that you can use both
> double and single quotes.

where can i set that?

> 2. for using single quote in your string you need to put one more single
> quote.
[quoted text clipped - 3 lines]
> 25')
> please note it looks like double quote it is not, it is 2 single quotes.

i got a syntax error here
Amarnath - 30 Mar 2007 06:16 GMT
You need to set in the data tab itself. e.g

SET QUOTED_IDENTIFIER OFF
exec
("Select * from Customers where Name= " + " ' " +@NAMEC+ " ' " + " and
AGECUST > 25")

Just paste this in your data tab it will work. ps: To make it clear I have
left space in between the double quotes. once you get the idea you can remove
the space. Just to check whether the sql query is correct just replace "exec"
with "select"

you will get the full query itself for you to check.

Amarnath, MCTS


> > There is no special function for that. you can do in 2 ways.
> > 1. use double quotes and set quote identifier off so that you can use both
[quoted text clipped - 11 lines]
>
> i got a syntax error here
Willo - 30 Mar 2007 14:50 GMT
Thank! Amarnath, works great.

> You need to set in the data tab itself. e.g
>
[quoted text clipped - 13 lines]
>
> Amarnath, MCTS
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.