Showing posts with label conversion. Show all posts
Showing posts with label conversion. Show all posts

Tuesday, February 14, 2012

Character to date conversion

I am trying to write and insert statement that takes up a date value, such as,
Insert into tablename(date_column) values (date('some date', format));

I however do not know how exactly to convert a character string to transact sql date. can someone please lead me in correct direction? Some documentation could also help.

Thanks
--Shilpa

No special functions needed. Just insert it as text:

CREATE TABLE test
(
dateValue datetime
)
go
INSERT INTO test
VALUES ('2006-01-01T00:00:00')
go

As for format of datetime values, there are many different ways to format a date, but really only a couple of good ways. Look up "Date Data Types" in books online. It explains it really well.

|||I am new to MS domain. Couldn't get to Books online.
I attempted your suggested Insert statement. The problem is, my date format is different,
it appears as a 12 hour clock. The date shows as 05/12/2005 06:30:12 PM. The table design view shows it as general date. Could you suggest a format for this?

Thanks
S
|||INSERT INTO test
VALUES ('2006-01-01T00:00:00')

Sorry about the previous post. Your solution works without the T before time insertion.
Thanks,
S
|||

There is a copy of books online (not unsurprisingly) online:

http://msdn2.microsoft.com/en-us/ms130214(sql.90).aspx

You can also download it online. They update it quarterly, and this download is from April:

http://www.microsoft.com/downloads/details.aspx?FamilyID=be6a2c5d-00df-4220-b133-29c1e0b6585f&DisplayLang=en

Character conversion table

Hi,
I have been told a conversion table exist in either the master or the msdb
database which can do a character conversion of data before it is sent to a
subscriber. I am not not talking about character set conversion but about
the ability to modify named characters into another named character, e.g.
chr(10)+chr(13) into chr(13).
Does anybody know of such a table? I haven not been able to locate it.
Cheers
/Christian
its in the msdb database and its called MSdatatype_mappings. However, this
doesn't really do what you are looking for. Its pure datatype mappings, ie a
datatype in SQL Server to a datatype in access.
Query this table to get an idea of what it actually does.
I think what you want to do is to use a DTS transform to carry this form of
conversion out.
What type of a database are you replicating to?
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Christian Dam" <badeanden@._no_spam_hotmail.com> wrote in message
news:ex8Mr%23aiEHA.2848@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have been told a conversion table exist in either the master or the msdb
> database which can do a character conversion of data before it is sent to
a
> subscriber. I am not not talking about character set conversion but about
> the ability to modify named characters into another named character, e.g.
> chr(10)+chr(13) into chr(13).
> Does anybody know of such a table? I haven not been able to locate it.
> Cheers
> /Christian
>
|||Yep, I know the MSdatatype_mappings but unfortunately that's not the one I
was looking for. Your reply, however, have finally convinced me that table I
was told existed, actually do not exist.
For a customer we have set up a replication from SQL Server 2000 to DB2.
Originally the DB2 was located on Windows and everything worked fine. The
customer then moved DB2 to AIX resulting in the line feed characters got
transferred incorrectly, I'm guessing because of the differences between NT
and AIX (the LFCR vs. CR thingy).
Unfortunately I don't have much additional information. It could look like a
ODBC configuration problem, but we don't even know if it is a line feed
characters are transferred incorrectly if it appears within normal row data.
We are using the IBM DB2 ODBC driver version 7.01.00.88.
Thanks
/Christian
"Hilary Cotter" <hilaryk@.att.net> wrote in message
news:%23$LROydiEHA.2764@.TK2MSFTNGP11.phx.gbl...
> its in the msdb database and its called MSdatatype_mappings. However, this
> doesn't really do what you are looking for. Its pure datatype mappings, ie
a
> datatype in SQL Server to a datatype in access.
> Query this table to get an idea of what it actually does.
> I think what you want to do is to use a DTS transform to carry this form
of[vbcol=seagreen]
> conversion out.
> What type of a database are you replicating to?
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Christian Dam" <badeanden@._no_spam_hotmail.com> wrote in message
> news:ex8Mr%23aiEHA.2848@.TK2MSFTNGP10.phx.gbl...
msdb[vbcol=seagreen]
to[vbcol=seagreen]
> a
about[vbcol=seagreen]
e.g.
>
|||I know some people who are replicating to DB2 on AIX and are using IBM's
Open Direct (IIRC) driver to do so.
I am curious as to how you/they got the data from DB2/NT to DB2/AIX. Perhaps
something was translated incorrectly in this process.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Christian Dam" <badeanden@._no_spam_hotmail.com> wrote in message
news:eHj7TCeiEHA.140@.TK2MSFTNGP12.phx.gbl...
> Yep, I know the MSdatatype_mappings but unfortunately that's not the one I
> was looking for. Your reply, however, have finally convinced me that table
I
> was told existed, actually do not exist.
> For a customer we have set up a replication from SQL Server 2000 to DB2.
> Originally the DB2 was located on Windows and everything worked fine. The
> customer then moved DB2 to AIX resulting in the line feed characters got
> transferred incorrectly, I'm guessing because of the differences between
NT
> and AIX (the LFCR vs. CR thingy).
> Unfortunately I don't have much additional information. It could look like
a
> ODBC configuration problem, but we don't even know if it is a line feed
> characters are transferred incorrectly if it appears within normal row
data.[vbcol=seagreen]
> We are using the IBM DB2 ODBC driver version 7.01.00.88.
> Thanks
> /Christian
>
> "Hilary Cotter" <hilaryk@.att.net> wrote in message
> news:%23$LROydiEHA.2764@.TK2MSFTNGP11.phx.gbl...
this[vbcol=seagreen]
ie
> a
> of
> msdb
> to
> about
> e.g.
>
|||Unfortunately it is not option to change the drivers. We are stuck with
what's already installed. (The customer have VERY strict change management
processes in place)
I don't know how the data was transferred to DB2/AIX, but the problem we are
facing now is concerned with new data originating from SQL Server. Any old
data is not affected. However, I doubt if the customer changed any of the
replication settings when they made the switch.
Cheers
/Christian
"Hilary Cotter" <hilaryk@.att.net> wrote in message
news:ODyoLGeiEHA.2992@.TK2MSFTNGP12.phx.gbl...
> I know some people who are replicating to DB2 on AIX and are using IBM's
> Open Direct (IIRC) driver to do so.
> I am curious as to how you/they got the data from DB2/NT to DB2/AIX.
Perhaps[vbcol=seagreen]
> something was translated incorrectly in this process.
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Christian Dam" <badeanden@._no_spam_hotmail.com> wrote in message
> news:eHj7TCeiEHA.140@.TK2MSFTNGP12.phx.gbl...
I[vbcol=seagreen]
table[vbcol=seagreen]
> I
The[vbcol=seagreen]
> NT
like[vbcol=seagreen]
> a
> data.
> this
mappings,[vbcol=seagreen]
> ie
form[vbcol=seagreen]
the[vbcol=seagreen]
sent[vbcol=seagreen]
it.
>

Character Conversion

Hi,

I'm using an ETL tool called DecisionStream.

On a particular SQL Server, when it performs an insert, the degree character is being converted to a stacked bar:

source data: 1332 NS 4 Tall 32 oz
after insert: 1332 NS 4 Tall 32 oz

This works fine on my laptop with SQL Server, but for some reason, on the SQL Server at work, this behaviour occurs.

Any input would be great.

thanks,
d.you could use the ascii and char() functions to check the value of the character on each computer.
then check the differences between the server and your laptop's regional settings in control panel > regional settings.
also check the character set\code page that SQL is loaded with in both instances, there should be a discrepancy in one of those two locations.
if not check for gremlins.

example
select ASCII('')

select Char(176)

select ASCII('|')

select Char(124)

Books Online {String Functions}|||I'd also check the column collations, and verify that the data path (including any temp files, network filters, etc) all support Unicode. I've been bitten more than once by character set conversions.

-PatP|||just made a huge oversite...the delivery where the character conversion is happening is not INSERTing (as I originally thought)...it is actually performing a BCP delivery...

Perhaps this stuff would make sense to one of you guys, as I don't know this utility very well.

TARGET TABLE DDL:

CREATE TABLE "dbo"."F_conv"
(
"col1" VARCHAR(21) NOT NULL
)
;

The .fmt file DecisionStream creates:

8.0
1
1 SQLCHAR 0 30 "\r\n" 1 col1 ""

the .dat file

1332 NS 4 Tall 32 oz

and the command:

bcp "MY_DB"."dbo"."F_conv" in "mydata.dat"
-q -S<server> -Usa -Psa -f"myformat.fmt"

thoughts? Tweaks to that fmt?|||Strictly as a test, try using:CREATE TABLE "dbo"."F_conv"
(
"col1" NVARCHAR(21) NOT NULL
)
;-PatP|||changing it to NVARCHAR delivered:

1332 NS 4░ Tall 32 oz|||can anyone successfully load via BCP the character:

actually...i'm going to start a new thread for this...

Sunday, February 12, 2012

Char to Base64 conversion

Hello. Anyone know a way to convert a char string into
BASE64? I'm loading some data to Active Directory from
SQL Server using an LDIF script and since there are
carriage returns imbedded, I BELEIVE the only way to do
this is BASE64 encoding. We wrote a function that loops
thru every character and converts it, but when doing a
large select, that encoding function takes too long for
each row.
INPUT CHAR STRING = "Hello World"
OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
Any ideas or hidden functions that do this conversion in
SQL Server? THanks, BruceCheckout the "FOR XML, BINARY BASE64" of the Select statement and see if it
helps you!
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:427201c49029$2a59bec0$a301280a@.phx.gbl...
> Hello. Anyone know a way to convert a char string into
> BASE64? I'm loading some data to Active Directory from
> SQL Server using an LDIF script and since there are
> carriage returns imbedded, I BELEIVE the only way to do
> this is BASE64 encoding. We wrote a function that loops
> thru every character and converts it, but when doing a
> large select, that encoding function takes too long for
> each row.
> INPUT CHAR STRING = "Hello World"
> OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
> Any ideas or hidden functions that do this conversion in
> SQL Server? THanks, Bruce|||wow, NICE!!! I've been doing some reading on that, and it
doesn't appear that it will convert a CHAR type field into
BINARY BASE64 but if you do the convert something like
this below, then you get it back as BASE64, very cool!
BUT, I'd like to strip the XML tags off, probably a
command to get it with just the straight BASE64 code?
Thanks a LOT, that was a great help!!
select top 1 convert(varbinary(8000),name) as 'name_binary'
from sysobjects
for XML RAW, BINARY BASE64
Thanks, Bruce
>--Original Message--
>Checkout the "FOR XML, BINARY BASE64" of the Select
statement and see if it
>helps you!
>
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:427201c49029$2a59bec0$a301280a@.phx.gbl...
>> Hello. Anyone know a way to convert a char string into
>> BASE64? I'm loading some data to Active Directory from
>> SQL Server using an LDIF script and since there are
>> carriage returns imbedded, I BELEIVE the only way to do
>> this is BASE64 encoding. We wrote a function that loops
>> thru every character and converts it, but when doing a
>> large select, that encoding function takes too long for
>> each row.
>> INPUT CHAR STRING = "Hello World"
>> OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
>> Any ideas or hidden functions that do this conversion in
>> SQL Server? THanks, Bruce
>
>.
>|||Hi Harman, Hi Bruce,
I am currently running into the same problem. I can convert it using the
technique you already mentione, but I can not put it into a variable to
strip off the XML-tags.
Do you have an idea how this could be done?
I tried to select it into a variable (not allowed) and tried to get it tino
a temp-table without success.
Maybe you could be so kind and give me a hint on that ;)
Thanks a lot in advance,
Andreas Bretl
andreas.bretl@.brainlab.com|||Andy, yes, the XML method was sooooooooo close... but no
cigar for the SAME reasons you mentioned! Amazing those
points you found that we did (and a zillion other did
also!). Maybe MS will fix that in the next release...
ANYWAY....... We ended up writing a SQL function, that
went thru the not-so-easy task of converting every
character to BASE64. There may be a better way with the
XML option, but we were ok with the function method for
our purposes. It's also pretty amazing that we have to
jump thru these hoops to stick a carriage return inside
an address block of lines, to send to AD, via an LDIF
script. BASE64 doesn't make for readable code at all,
strange that was needed, but it's working fine after we
figured out all the klooge... Bruce
>--Original Message--
>Hi Harman, Hi Bruce,
>I am currently running into the same problem. I can
convert it using the
>technique you already mentione, but I can not put it
into a variable to
>strip off the XML-tags.
>Do you have an idea how this could be done?
>I tried to select it into a variable (not allowed) and
tried to get it tino
>a temp-table without success.
>Maybe you could be so kind and give me a hint on that ;)
>Thanks a lot in advance,
>Andreas Bretl
>andreas.bretl@.brainlab.com
>
>.
>|||Hi Bruce,
I totally agree, that one was really close at all ;)
I ended up in a COM-DLL I installed on the server where I implemented the
Base64 algo. called via sp_OAMethod.
It works fine but it is strange that such a "simple" thing causes so much
workaround.
Do you think there is a chance to see how you handled it with the SQL
function?
I totally understand if you have to keep it "secret" but I just thought
asking could't harm anybody ;)
Seize the Day
Andy
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:114301c4a5c0$23054bb0$a601280a@.phx.gbl...
> Andy, yes, the XML method was sooooooooo close... but no
> cigar for the SAME reasons you mentioned! Amazing those
> points you found that we did (and a zillion other did
> also!). Maybe MS will fix that in the next release...
> ANYWAY....... We ended up writing a SQL function, that
> went thru the not-so-easy task of converting every
> character to BASE64. There may be a better way with the
> XML option, but we were ok with the function method for
> our purposes. It's also pretty amazing that we have to
> jump thru these hoops to stick a carriage return inside
> an address block of lines, to send to AD, via an LDIF
> script. BASE64 doesn't make for readable code at all,
> strange that was needed, but it's working fine after we
> figured out all the klooge... Bruce
> > >

Char to Base64 conversion

Hello. Anyone know a way to convert a char string into
BASE64? I'm loading some data to Active Directory from
SQL Server using an LDIF script and since there are
carriage returns imbedded, I BELEIVE the only way to do
this is BASE64 encoding. We wrote a function that loops
thru every character and converts it, but when doing a
large select, that encoding function takes too long for
each row.
INPUT CHAR STRING = "Hello World"
OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
Any ideas or hidden functions that do this conversion in
SQL Server? THanks, BruceCheckout the "FOR XML, BINARY BASE64" of the Select statement and see if it
helps you!
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:427201c49029$2a59bec0$a301280a@.phx.gbl...
> Hello. Anyone know a way to convert a char string into
> BASE64? I'm loading some data to Active Directory from
> SQL Server using an LDIF script and since there are
> carriage returns imbedded, I BELEIVE the only way to do
> this is BASE64 encoding. We wrote a function that loops
> thru every character and converts it, but when doing a
> large select, that encoding function takes too long for
> each row.
> INPUT CHAR STRING = "Hello World"
> OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
> Any ideas or hidden functions that do this conversion in
> SQL Server? THanks, Bruce|||wow, NICE!!! I've been doing some reading on that, and it
doesn't appear that it will convert a CHAR type field into
BINARY BASE64 but if you do the convert something like
this below, then you get it back as BASE64, very cool!
BUT, I'd like to strip the XML tags off, probably a
command to get it with just the straight BASE64 code?
Thanks a LOT, that was a great help!!
select top 1 convert(varbinary(8000),name) as 'name_binary'
from sysobjects
for XML RAW, BINARY BASE64
Thanks, Bruce

>--Original Message--
>Checkout the "FOR XML, BINARY BASE64" of the Select
statement and see if it
>helps you!
>
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:427201c49029$2a59bec0$a301280a@.phx.gbl...
>
>.
>|||Hi Harman, Hi Bruce,
I am currently running into the same problem. I can convert it using the
technique you already mentione, but I can not put it into a variable to
strip off the XML-tags.
Do you have an idea how this could be done?
I tried to select it into a variable (not allowed) and tried to get it tino
a temp-table without success.
Maybe you could be so kind and give me a hint on that ;)
Thanks a lot in advance,
Andreas Bretl
andreas.bretl@.brainlab.com|||Andy, yes, the XML method was sooooooooo close... but no
cigar for the SAME reasons you mentioned! Amazing those
points you found that we did (and a zillion other did
also!). Maybe MS will fix that in the next release...
ANYWAY....... We ended up writing a SQL function, that
went thru the not-so-easy task of converting every
character to BASE64. There may be a better way with the
XML option, but we were ok with the function method for
our purposes. It's also pretty amazing that we have to
jump thru these hoops to stick a carriage return inside
an address block of lines, to send to AD, via an LDIF
script. BASE64 doesn't make for readable code at all,
strange that was needed, but it's working fine after we
figured out all the klooge... Bruce

>--Original Message--
>Hi Harman, Hi Bruce,
>I am currently running into the same problem. I can
convert it using the
>technique you already mentione, but I can not put it
into a variable to
>strip off the XML-tags.
>Do you have an idea how this could be done?
>I tried to select it into a variable (not allowed) and
tried to get it tino
>a temp-table without success.
>Maybe you could be so kind and give me a hint on that ;)
>Thanks a lot in advance,
>Andreas Bretl
>andreas.bretl@.brainlab.com
>
>.
>|||Hi Bruce,
I totally agree, that one was really close at all ;)
I ended up in a COM-DLL I installed on the server where I implemented the
Base64 algo. called via sp_OAMethod.
It works fine but it is strange that such a "simple" thing causes so much
workaround.
Do you think there is a chance to see how you handled it with the SQL
function?
I totally understand if you have to keep it "secret" but I just thought
asking could't harm anybody ;)
Seize the Day
Andy
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:114301c4a5c0$23054bb0$a601280a@.phx.gbl...[vbcol=seagreen]
> Andy, yes, the XML method was sooooooooo close... but no
> cigar for the SAME reasons you mentioned! Amazing those
> points you found that we did (and a zillion other did
> also!). Maybe MS will fix that in the next release...
> ANYWAY....... We ended up writing a SQL function, that
> went thru the not-so-easy task of converting every
> character to BASE64. There may be a better way with the
> XML option, but we were ok with the function method for
> our purposes. It's also pretty amazing that we have to
> jump thru these hoops to stick a carriage return inside
> an address block of lines, to send to AD, via an LDIF
> script. BASE64 doesn't make for readable code at all,
> strange that was needed, but it's working fine after we
> figured out all the klooge... Bruce

Char to Base64 conversion

Hello. Anyone know a way to convert a char string into
BASE64? I'm loading some data to Active Directory from
SQL Server using an LDIF script and since there are
carriage returns imbedded, I BELEIVE the only way to do
this is BASE64 encoding. We wrote a function that loops
thru every character and converts it, but when doing a
large select, that encoding function takes too long for
each row.
INPUT CHAR STRING = "Hello World"
OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
Any ideas or hidden functions that do this conversion in
SQL Server? THanks, Bruce
Checkout the "FOR XML, BINARY BASE64" of the Select statement and see if it
helps you!
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:427201c49029$2a59bec0$a301280a@.phx.gbl...
> Hello. Anyone know a way to convert a char string into
> BASE64? I'm loading some data to Active Directory from
> SQL Server using an LDIF script and since there are
> carriage returns imbedded, I BELEIVE the only way to do
> this is BASE64 encoding. We wrote a function that loops
> thru every character and converts it, but when doing a
> large select, that encoding function takes too long for
> each row.
> INPUT CHAR STRING = "Hello World"
> OUTPUT BASE64 STRING = "SGVsbG8gV29ybGQ="
> Any ideas or hidden functions that do this conversion in
> SQL Server? THanks, Bruce
|||wow, NICE!!! I've been doing some reading on that, and it
doesn't appear that it will convert a CHAR type field into
BINARY BASE64 but if you do the convert something like
this below, then you get it back as BASE64, very cool!
BUT, I'd like to strip the XML tags off, probably a
command to get it with just the straight BASE64 code?
Thanks a LOT, that was a great help!!
select top 1 convert(varbinary(8000),name) as 'name_binary'
from sysobjects
for XML RAW, BINARY BASE64
Thanks, Bruce

>--Original Message--
>Checkout the "FOR XML, BINARY BASE64" of the Select
statement and see if it
>helps you!
>
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
>news:427201c49029$2a59bec0$a301280a@.phx.gbl...
>
>.
>
|||Hi Harman, Hi Bruce,
I am currently running into the same problem. I can convert it using the
technique you already mentione, but I can not put it into a variable to
strip off the XML-tags.
Do you have an idea how this could be done?
I tried to select it into a variable (not allowed) and tried to get it tino
a temp-table without success.
Maybe you could be so kind and give me a hint on that ;)
Thanks a lot in advance,
Andreas Bretl
andreas.bretl@.brainlab.com
|||Andy, yes, the XML method was sooooooooo close... but no
cigar for the SAME reasons you mentioned! Amazing those
points you found that we did (and a zillion other did
also!). Maybe MS will fix that in the next release...
ANYWAY....... We ended up writing a SQL function, that
went thru the not-so-easy task of converting every
character to BASE64. There may be a better way with the
XML option, but we were ok with the function method for
our purposes. It's also pretty amazing that we have to
jump thru these hoops to stick a carriage return inside
an address block of lines, to send to AD, via an LDIF
script. BASE64 doesn't make for readable code at all,
strange that was needed, but it's working fine after we
figured out all the klooge... Bruce

>--Original Message--
>Hi Harman, Hi Bruce,
>I am currently running into the same problem. I can
convert it using the
>technique you already mentione, but I can not put it
into a variable to
>strip off the XML-tags.
>Do you have an idea how this could be done?
>I tried to select it into a variable (not allowed) and
tried to get it tino
>a temp-table without success.
>Maybe you could be so kind and give me a hint on that ;)
>Thanks a lot in advance,
>Andreas Bretl
>andreas.bretl@.brainlab.com
>
>.
>
|||Hi Bruce,
I totally agree, that one was really close at all ;)
I ended up in a COM-DLL I installed on the server where I implemented the
Base64 algo. called via sp_OAMethod.
It works fine but it is strange that such a "simple" thing causes so much
workaround.
Do you think there is a chance to see how you handled it with the SQL
function?
I totally understand if you have to keep it "secret" but I just thought
asking could't harm anybody ;)
Seize the Day
Andy
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:114301c4a5c0$23054bb0$a601280a@.phx.gbl...[vbcol=seagreen]
> Andy, yes, the XML method was sooooooooo close... but no
> cigar for the SAME reasons you mentioned! Amazing those
> points you found that we did (and a zillion other did
> also!). Maybe MS will fix that in the next release...
> ANYWAY....... We ended up writing a SQL function, that
> went thru the not-so-easy task of converting every
> character to BASE64. There may be a better way with the
> XML option, but we were ok with the function method for
> our purposes. It's also pretty amazing that we have to
> jump thru these hoops to stick a carriage return inside
> an address block of lines, to send to AD, via an LDIF
> script. BASE64 doesn't make for readable code at all,
> strange that was needed, but it's working fine after we
> figured out all the klooge... Bruce