Insert Binary Data with APOSTROPHE

  • Thread starter Thread starter Uma
  • Start date Start date
U

Uma

Hi pals,

I am trying to insert binary data in to a field(data type:binary) of a
table. Facing a problem with inserting if the binary data contains
APOSTROPHE ( ' ). SQL Server expects another APOSTROPHE to end the data.
How could I insert that type of data into a binary field ? Could you please
guide me?

regards,
Shahul.
 
binary data type accepts only hexadecimal values....how can you obtain an
apostrophe from an hexadecimal representation of a bit string??
Can you post some example of your insert statement?

Francesco Anti
 
The following queries are working fine:

create table binarytest(binfield binary(100))

1.insert into binarytest values(cast('123' as binary(10)))
2.insert into binarytest values(cast(123 as binary(10)))
3.insert into binarytest values(cast('aesdgA?v' as binary(10)))

What should be done if I want to execute the following query?

insert into binarytest values(cast(aesdg'A?v as binary(10)))

Binary data : aesdg'A?v

For apostrophe, the hexadecimal value is 27, decimal value is 39

This statement is required since we are actually inserting into this table
through an stored procedure which we are calling in C program. In C program
we are sending binary data, which may also contain apostrohpe('), comma(,),
space( ) and many more characters.

Regards,
Shahul
 
Since you express the data as a string before the cast, do the same as usual, double each
single-quote:

insert into binarytest values(cast('aesdg''A?v' as binary(10)))
 
To add to Tibor's response, consider passing the value as a properly typed
parameter you application program:

CREATE PROCEDURE InsertBinaryTest
@BinaryData binary(10)
AS
INSERT INTO binarytest VALUES(@BinaryData)
GO

EXEC InsertBinaryTest @BinaryData = 0x6165736467413F760000
 
Hi pals,

I am trying to insert binary data in to a field(data type:binary) of a
table. Facing a problem with inserting if the binary data contains
APOSTROPHE ( ' ). SQL Server expects another APOSTROPHE to end the data.
How could I insert that type of data into a binary field ? Could you please
guide me?

regards,
Shahul.
ge ziet ne sukel ahhahahahaha
 
Actually I need to store the Apostrophe in the binary data itself. What can
I do if so?
We can use the method as '''' (four apostrophe) for inserting a single
apostrophe, Is any other flexible method available? I won't check the
Apostrophe present in the binary data or not, when I am calling the Stored
Procedure in my C program.
 
I'm not sure what you are saying here. In your example, you express the text information as a
string, then CAST it to binary. But as you express it as a string, you need to follow the rules for
string handling. Those rules are that you enclose the string within single-quotes. And if you want
to express a single-quote inside the string, you escape that single-quote with another single-quote
(double it).
 
Back
Top