Hi
Declare @.Customer varchar(255)
Set @.Customer = Single quotes + customer name + single quotes
Select Customerid from Customer Where name = @.Customer
I have a query written above, but i was not able to add single quotes to the set statement above. Can i know as how to go about it?
Early reply is much appreciated.
Thanks!
You can not write?
set @.Customer = 'customer name'
What is the problem with writing that? Do you get an error?
|||
Nopes, here iam using a variable called "customer name" to which values will be passed in dynamically,
so the query is like
set @.Customer = single quotes + customer name(variable) + single quotes
Hope it is clear, or else if you need more information let me know.
Thanks!
|||
try this....
'''' + Customer Name + ''''
If you want to give the Single Quote on String Litteral you need to use 2 Single Quote Continuously..
-mani
|||set @.Customer = '''' + CustomerName + ''''|||hey...
char(39) is the ascii for single quotes...
declare @.sql varchar(110)
set @.sql = 'select char(39)+name1+char(39) from test_name'
exec (@.gg)
--assuming test_name has 2 records mak and robin , so the output is
'MAK'
'ROBIN'
|||edukulla wrote: Nopes, here iam using a variable called "customer name" to which values will be passed in dynamically,
so the query is like
set @.Customer = single quotes + customer name(variable) + single quotes
Still not clear, a few more questions unless the other replies helped you.
What kind of variable is customer name?
How do you want to execute the SQL statements?
If you are doing this in a programming language, what programming language?
Hello,
If your issue is that you are having difficulties finding a way to deal with character string which may contain one or more single quotes, then the solution is NOT to surround the string with single quotes as a previous user suggested. This will only work if there is in fact onle one single quote in your string such as O'Brian. It will not work if there are multiple quotes such as Here's O'Brian.
SET QUOTED_IDENTIFIER OFF
DECLARE @.s VARCHAR(100)
SET @.s = " Here's O'Brian and some quotes: ''''''''' "
PRINT @.s
Cheers,
Rob
No comments:
Post a Comment