Groups | Blog | Home
all groups > sql server reporting services > march 2007 >

sql server reporting services : A QuotedStr function


Willo
3/28/2007 11:44:19 AM
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
3/29/2007 4:24:01 AM
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


[quoted text, click to view]
Willo
3/29/2007 8:50:59 AM
[quoted text, click to view]

where can i set that?

[quoted text, click to view]

i got a syntax error here



Amarnath
3/29/2007 10:16:03 PM
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



[quoted text, click to view]
Willo
3/30/2007 7:50:15 AM
Thank! Amarnath, works great.

[quoted text, click to view]

AddThis Social Bookmark Button