Hi
this is my query
SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE BusinessName like @BusinessName + '%' ...
When i execute my SP output Shouldbe like this
AccountNo BusinessName
10509 Anderson's "The Grocery Store".......
But when iexecut emy SP
--EXEC DBSP_SF_GetAccountsLikeAccNo '10509','Anderson's "The Grocery Store"'
Getting error like...........
Incorrect syntax near 's'.
Unclosed quotation mark after the character string ''.
So when i execute my SP adding another Apostrophe after anderson
like EXEC DBSP_SF_GetAccountsLikeAccNo '10509','Anderson''s "The Grocery Store"'
ite executed so i want to replace how to replace using replace function in SP
plz help me
Loading
Guest UserPosted Sep 13, 2011, 12:25 PM
BusinessName = BusinessName.Replace("'", "\\\'");
Guest UserPosted Sep 12, 2011, 1:15 PM
REPLACE(@BusinessName, '''', '''''')
You're telling the db engine to find instances of single quotes in the string, replace them with two single quotes and return the results. In your example, Anderson's becomes Anderson''s which is what you want to search by.
'''' is interpreted by the engine as a string that contains one single quote.
'''''' is interpreted by the engine as a string that contains two single quotes.
Satyapriya NayakPosted Sep 14, 2011, 5:08 AM
Here is your solution
SELECT *
FROM CustomerDetails
WHERE (BusinessName LIKE '%''%') OR
(BusinessName LIKE '%"%')
Thanks
If this post helps you mark it as answer
karthik parchaPosted Sep 14, 2011, 2:34 AM
This is my query SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) it retreving the data but
it retreving only the data with out single and double quotes
In my database there are Businessnames like single quotes and double quotes 109 rows are there ...
For retreving only sigle and double quotes query i
select * from CustomerDetails where BusinessName like '%"%'
the data with single quotes and double quotes are not retreving
Plz help me how to retreive normal data and single and double quotes data also from data base
karthik parchaPosted Sep 14, 2011, 1:22 AM
Thank u for your patience sometimes it happens john i can understand your problem .......... its working john.......................
thank u thank u so much john its displaying in textbox now link button is also firing.......you are helping me alot john ...........
karthik parchaPosted Sep 13, 2011, 11:49 AM
karthik parchaPosted Sep 13, 2011, 11:48 AM
"'" is also inserrting in textbox
karthik parchaPosted Sep 13, 2011, 10:54 AM
i will try this if there any issues i will contact you
thanks
karthik
Guest UserPosted Sep 13, 2011, 10:34 AM
Guest UserPosted Sep 13, 2011, 10:20 AM
BusinessName = BusinessName.Replace("'", "'");
karthik parchaPosted Sep 13, 2011, 9:28 AM
karthik parchaPosted Sep 13, 2011, 9:02 AM
HyperLink hfAccount = (HyperLink)e.Row.FindControl("hfgvAccountNo");
Label lblBusinessName = (Label)e.Row.FindControl("lblgvBusinessName");
string BusinessName = Convert.ToString(lblBusinessName.Text);
BusinessName = BusinessName.Replace("'", "\'");
//// BusinessName = BusinessName.Replace("'", "'");
hfAccount.Attributes.Add("onclick", "javascript:return UpdateParentWindow('" + hfAccount.Text + "','" + BusinessName + "','" + ViewState["CtrlAcc"] + "','" + ViewState["CtrlBName"] + "')");
not replacing when i debug through the application iam getting text like
lblbusinessname={Text=Anderson's\ "The Grocery Store\""}
i have to place Anderson's "The Grocery Store" into textbox plz help me
I dont know why the link button is not firing when the text is like Anderson's "The Grocery Store"
But when the text is like Andersons the grocery store with out any single quotes its displaying in textbox
Guest UserPosted Sep 13, 2011, 8:56 AM
karthik parchaPosted Sep 13, 2011, 8:51 AM
When i changed my code like this its working and linkbutton is firing displaying text in textbox but it displaying " also in textbox.......
John i tried your code not replacing singlequotes and link button is not firing plz do u have any other idea plz can change code for me
Guest UserPosted Sep 13, 2011, 8:42 AM
karthik parchaPosted Sep 13, 2011, 8:27 AM
I tried Your COde sory its not working
Itried like this
HyperLink hfAccount = (HyperLink)e.Row.FindControl("hfgvAccountNo");
Label lblBusinessName = (Label)e.Row.FindControl("lblgvBusinessName");
string BusinessName = Convert.ToString(lblBusinessName.Text);
BusinessName = BusinessName.Replace("'", "'");
hfAccount.Attributes.Add("onclick", "javascript:return UpdateParentWindow('" + hfAccount.Text + "','" + BusinessName + "','" + ViewState["CtrlAcc"] + "','" + ViewState["CtrlBName"] + "')");
When i click thelink button which contains businessname single quotes and double quotes the businessname is displaying in textbox like
Anderson's "The Grocery Store"... where should i have to change the code
plz help me from 2 days iam trying this
Guest UserPosted Sep 13, 2011, 8:07 AM
hfAccount.Attributes.Add("onclick", "javascript: UpdateParentWindow('"+hfAccount.Text+"','"+lblBusinessName.Text.Replace("'", "\'") +"','"+ViewState["CtrlAcc"]+"','"+ViewState["CtrlBName"]+"')");
You have to escape the single quotes in the business name because you're using single quotes to delimit the strings in the javascript statement.
karthik parchaPosted Sep 13, 2011, 5:27 AM
karthik parchaPosted Sep 13, 2011, 1:50 AM
i have one issue inmy application
in my gridview there so many fileds like
1.AccountnO 2.Businessname these are columns in that for accountnumber i have textbox then clicked on the (...) button immediate to the right of the account number field
when i clicked this button businessname is retreived in one window
in that accountnumber is link button and businessname is label.
when i click the linkbutton that businesname should be placed in businesscolumn textbox...
so my issue is
when the text with single quotes Anderson's "The Grocery Store" is not placing in text box
but when the text with Andersons The Grocery Store is placing in textbox can u plz help me this is my code
iam getting error like javascript error occured
protected void gvAccounts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = (DataRowView)e.Row.DataItem;
if (dr != null)
{
HyperLink hfAccount = (HyperLink)e.Row.FindControl("hfgvAccountNo");
Label lblBusinessName = (Label)e.Row.FindControl("lblgvBusinessName");
//string BusinessName = lblBusinessName.ToString();
//string newBusName=BusinessName.Replace("\"," ");
hfAccount.Attributes.Add("onclick", "javascript: UpdateParentWindow('"+hfAccount.Text+"','"+lblBusinessName.Text+"','"+ViewState["CtrlAcc"]+"','"+ViewState["CtrlBName"]+"')");
}
}
}
karthik parchaPosted Sep 12, 2011, 1:01 PM
Its working John
(@BusinessName, '''', '''''')
Why you written this many single quotes can u explain john plz it will be easy to remember for me again when this issue comes to me
thanks alot john
karthik
Guest UserPosted Sep 12, 2011, 12:28 PM
DECLARE @foo VARCHAR(100)
SET @foo = 'Anderson''s'
Try the REPLACE function in your procedure as follows:
ALTER PROCEDURE [dbo].[DBSP_SF_GetAccountsLikeAccNo]
@AccountNo VARCHAR(20),
@BusinessName VARCHAR(40),
@Type VARCHAR(2)
AS
BEGIN
IF @Type = 'AN'
BEGIN
SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE AccountNo like REPLACE(@AccountNo, '''', '''''') + '%'
END
ELSE IF @Type = 'BN'
BEGIN
SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE BusinessName like REPLACE(@BusinessName, '''', '''''') + '%'
END
END
karthik parchaPosted Sep 12, 2011, 5:41 AM
ALTER PROCEDURE [dbo].[DBSP_SF_GetAccountsLikeAccNo]
@AccountNo VARCHAR(20),
@BusinessName VARCHAR(40),
@Type VARCHAR(2)
AS
BEGIN
IF @Type = 'AN'
BEGIN
SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE AccountNo like @AccountNo + '%'
END
ELSE IF @Type = 'BN'
BEGIN
SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE BusinessName like @BusinessName + '%'
END
END