Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL - How do I save anything?

Author  Topic 

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-27 : 17:00:34
I am trying to write an email application. I am able to download messages (Pop3) and would like to save them unchanged to a database table.

Is there a way to write a SELECT INTO statement that will do so without having to worry about special characters?

If not, would saving them to a random access file be easier?

I will welcome all suggestions.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-27 : 17:03:33
Regarding special characters, you would need to use one of the unicode data types such as nvarchar.

Why are you reinventing the wheel though?

Random access file?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-27 : 17:57:34
Hi Tara,
I don't want to use random access, I would like to use a database. Please explain "you would need to use one of the unicode data types such as nvarchar" and can you supply an example.
Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-27 : 18:07:53
I'm not suggesting to use random access, I am asking what you mean by that.

The unicode data types allow storing of double-byte data such as chinese characters, I assume that's what you meant by special characters in your original post. As for an example: create table t1 (c1 nvarchar(50)).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-27 : 18:16:28
Sorry, I was talking about characters such as " ' & () [] etc. I don't want to have the program go through a long email with all sorts of attachments adding or changing characters in order to be able to save it. I was asking if there is a way to write a SELECT INTO statement that will avoid that.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-27 : 18:30:08
If you want to remove characters like that, then you could use REPLACE and nest them. REPLACE(col1, '$', '') --> REPLACE(REPLACE(col1, '$', ''), '%', '')...

I wouldn't remove characters though as there's no problem saving those kinds of characters to a SQL table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-27 : 18:35:32
You say, "I wouldn't remove characters though as there's no problem saving those kinds of characters to a SQL table". That's great - exactly what I want! Please give me an example of an INSERT INTO statement that will save anything I put into it.
Go to Top of Page

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-27 : 18:40:51
By the way, there are only 2 fields in the table, ID (autoincreasing) and Message (string). I want to save the email message in its original form in the Message field.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-27 : 21:43:00
There's nothing special about saving special characters, your examples are just simple data.

INSERT INTO SomeTable (Message) VALUES ('SomeData')
INSERT INTO SomeTable (Message) VALUES ('$SomeMoreD@ta!)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonLoukes
Starting Member

6 Posts

Posted - 2011-12-28 : 18:44:31
Thanks Tara

I eventually solved my problem by using a paramatized Insert Into statement.

Regards.
Go to Top of Page
   

- Advertisement -