473,473 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Single Quotes in a dynamic SQL

31 New Member
Hi I want to know how can we use single quotted string as a part of dynamic sql
Consider the following code

exec('select branchid from '+@tablename+' where Entrystatus='NEW' AND BranchName= '+@branchname')
In the above query New is string like 'NEW'and BranchName is also a string so how am I suppose to write single quotes?
wht is the main funda behind using them?
thnks
Apr 21 '09 #1
5 13804
Uncle Dickie
67 New Member
Does this article help?
Apr 21 '09 #2
jvskarthick
13 New Member
exec('select branchid from '+@tablename+' where Entrystatus=''NEW'' AND BranchName= '+@branchname')

Just change 'NEW' to ''NEW'' and try it...

Reg,
JK
Apr 21 '09 #3
Delerna
1,134 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. exec(
  2.    'select branchid 
  3.    from '+@tablename+' 
  4.    where Entrystatus=' + char(39)+'NEW' +char(39) +'
  5.    AND BranchName= '+ char(39) + @branchname + char(39)
  6. )
  7.  
or this might look cleaner to read
Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @New
  3. set @New=char(39) + 'NEW' + char(39)
  4. set @branchname=char(39) + @branchname + char(39)
  5. exec('select branchid from ' + @tablename + ' where Entrystatus=' + @New +' AND BranchName= ' + @branchname)
  6.  
39 is the ASCII code for a single quote
Apr 22 '09 #4
Delerna
1,134 Recognized Expert Top Contributor
and as Uncle dickie highlights

this
select 'test '''+'hello'+''' test'

also works
interresting !
Apr 22 '09 #5
SnehaAgrawal
31 New Member
thnks for the solution
Apr 23 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
3
by: Ian Griffiths | last post by:
I'm having issues witht the code I'm writing. I've dealt with SQL before, although only for extracting data, not adding it to the database. I've been intensively learning ASP/ADO over the past week...
2
by: asd987 | last post by:
Hi, I use document.write in a HTML-document to display same information. Now I have a problem displaying text that sometimes contains two kinds of quotes simultanelisly. I don't know on...
10
by: JJA | last post by:
I'm trying to use document.getElementByID inside a function where the ID is passed as an argument. I get the same error ("Element has no properties") on the same statement inside the commonCheck...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
3
by: Jon Maz | last post by:
Hi, A quick one: If you are forming a dynamic sql statement using parameters from a web form, you would normally double up any single inverted commas inputted by the user to stop sql...
11
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
2
by: Reporter | last post by:
I got the following example from http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/index.html : echo '<tr><td>First name:</td><td><input type="text" name="first_name"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.