all groups > sql server mseq > april 2004 >
You're in the

sql server mseq

group:

Inserting a string with an Apostrophe


Inserting a string with an Apostrophe CB
4/29/2004 1:16:04 PM
sql server mseq:
I would like to insert a value with an apostrophe into a character field. I keep on getting "commande text not set for command object". Is there a character that I can put before and after the string to show that the system should take the exact value and not look at the characters as an indicator
Re: Inserting a string with an Apostrophe CB
4/29/2004 2:06:02 PM
That worked perfectly - excpet what do i do if the value is a variable and not a constant

Ex: VariableName = 'D'mario
Insert into NAME (LASTNAME) Values ('VariableName'
So i do not know exactly where the apostrophe is

Thank you so much for your help


----- Vishal Parkar wrote: ----

double up the single quote

Insert into NAME (LASTNAME) Values ('D''Mario'

--
Vishal Parka
vgparkar@yahoo.co.i

"CB" <anonymous@discussions.microsoft.com> wrote in messag
news:2EB35DAE-25A4-4CA2-BE04-AA1FCD64F3BC@microsoft.com..
[quoted text, click to view]
field. I keep on getting "commande text not set for command object". I
there a character that I can put before and after the string to show tha
the system should take the exact value and not look at the characters as a
indicator
[quoted text, click to view]


Re: Inserting a string with an Apostrophe CB
4/29/2004 2:26:09 PM
I am trying to do this from an existing list of names so I can not do that. Any ideas
Re: Inserting a string with an Apostrophe CB
4/29/2004 6:26:05 PM
Let me try to explain

I am compiling information about tenants that is stored in a few different tables and populating a new table with the gathered data. So the processes is as follows -
1. read in a record from the SourceTabl
2. assign the variable
3. write the data into the DestinationTable using the assigned variable

So the Names are coming from an existing table. I can not easily change D'Angilo to D''Angilo

Re: Inserting a string with an Apostrophe Vishal Parkar
4/30/2004 2:13:15 AM
double up the single quote.

Insert into NAME (LASTNAME) Values ('D''Mario')

--
Vishal Parkar
vgparkar@yahoo.co.in

[quoted text, click to view]
field. I keep on getting "commande text not set for command object". Is
there a character that I can put before and after the string to show that
the system should take the exact value and not look at the characters as an
indicator?
[quoted text, click to view]

Re: Inserting a string with an Apostrophe Vishal Parkar
4/30/2004 2:39:45 AM
change it in variable assignment itself.

Ex:
declare @VariableName varchar(50)
set @VariableName = 'D''mario'

--
Vishal Parkar
vgparkar@yahoo.co.in


Re: Inserting a string with an Apostrophe Vishal Parkar
4/30/2004 3:35:21 AM
didn't get you on this. from where are you picking up this list?

--
Vishal Parkar
vgparkar@yahoo.co.in

[quoted text, click to view]

Re: Inserting a string with an Apostrophe CB
4/30/2004 6:51:10 AM
Re: Inserting a string with an Apostrophe Vishal Parkar
4/30/2004 7:09:35 AM
hi cb,

When you assign the value to the variable using select statement, it
automatically picks up the single quote as it is. See following example.

--sample data
drop table t
create table t(name varchar(50))

insert into t values('Mc''donald')

--lets perform steps you've mentioned.
--1. read in a record from the SourceTable
--2. assign the variables

declare @x varchar(50)
select @x = name from t

--3. write the data into the DestinationTable using the assigned variables
-- insert the data into same table.

insert into t values (@x)

--check the data, you will see 2 rows with same values
select * from t

--
Vishal Parkar
vgparkar@yahoo.co.in


AddThis Social Bookmark Button