Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Unicode output from varchar data columns Expand / Collapse
Author
Message
Posted Thursday, July 25, 2013 11:07 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:15 PM
Points: 220, Visits: 71
This is a bit odd - I have a table in SQl Server 2005 Standard Edition defined like so:

CREATE TABLE [dbo].[RuleInput](
[SiteID] [varchar](9) NULL,
[ConID] [varchar](6) NULL,
[Email] [varchar](50) NULL,
[First] [varchar](400) NULL,
[Middle] [varchar](400) NULL,
[Last] [varchar](400) NULL,
[Language] [varchar](3) NULL,
[Source] [varchar](3) NOT NULL,
[Domain] [varchar](400) NULL,
[RuleID] [int] NOT NULL
) ON [PRIMARY]
END

I fill this table with data, no problems there.

Now I wish to send the output of the following query to a file:

SELECT R.[SiteID]
,R.[ConID]
,'' AS [Prefix]
,RTRIM(R.[First]) AS [First]
,RTRIM(R.[Middle]) AS Middle
,RTRIM(R.[Last]) AS [Last]

,RTRIM(R.[Email]) AS [Email]
,RTRIM(R.[Domain]) AS [Domain]
,[Source]
,[RuleID]
,R.[Language]
FROM [EmailWork].[dbo].[RuleInput] R

Using the "Results to File" toolbar item after setting the Query > Query Options like so:
Advanced tab: check the "Set Nocount" box
Text tab: Custom Delimiter - Pipe symbol, and uncheck the "Include column headers in result set" box

Here's my problem - the output file contains UNICODE for all of the text fields.

Collation for my database is: SQL_Latin1_General_CP1_CI_AS

Is there something I can do to set my default to ASCII?

Thanks in advance for any insight/help on this issue.

/john
Post #1477634
Posted Thursday, July 25, 2013 1:45 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
I don't know if this is a one shot (if it is, you can simply convert to ASCII with the free tool Notepad++), but if it isn't, you can use SSIS or bcp to extract the data to an ASCII text file.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1477710
Posted Thursday, July 25, 2013 2:10 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:15 PM
Points: 220, Visits: 71
Thanks for the reply. I used an SSIS package to output the file as ASCII text to meet my immediate need.

I would like to know if it's possible to change a database or table setting (or login setting?) to allow the Results to File query option to send the ASCII text properly rather than defaulting all text output to Unicode text.

Having to write a quicky SSIS package every time I want to generate file output from a table is not a big deal, but it sure seems like a waste.

/john
Post #1477728
Posted Thursday, July 25, 2013 2:13 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
jk_in_San_Diego (7/25/2013)
Thanks for the reply. I used an SSIS package to output the file as ASCII text to meet my immediate need.

I would like to know if it's possible to change a database or table setting (or login setting?) to allow the Results to File query option to send the ASCII text properly rather than defaulting all text output to Unicode text.

Having to write a quicky SSIS package every time I want to generate file output from a table is not a big deal, but it sure seems like a waste.

/john


I digged around for a bit, but could't really find a solutin within SSMS itself.
Like I said, you can quickly convert the file to ASCII with Notepad++. Just a few clicks.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1477735
Posted Thursday, July 25, 2013 2:17 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:15 PM
Points: 220, Visits: 71
Yeah, I know and love Notepad++ myself, but it is limited on the maximum file size that it can handle. Unfortunately, some of my text output files get up into the 6+ GB size.

/john
Post #1477737
Posted Thursday, July 25, 2013 2:29 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
jk_in_San_Diego (7/25/2013)
Yeah, I know and love Notepad++ myself, but it is limited on the maximum file size that it can handle. Unfortunately, some of my text output files get up into the 6+ GB size.

/john


Ah, that might be an issue




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1477742
Posted Thursday, July 25, 2013 3:49 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:15 PM
Points: 220, Visits: 71
File this under "you learn something new every day" - my coworker (Linda Knott - The Magnificent!) reminded me that the Save button during the file name prompt has a down-arrow. Clicking the down-arrow allows you to select "Save with encoding..." which allows you to choose Unicode (the default), ANSI (which is ASCII), or Chineese characters.

Huzza! Select the correct encoding for the type of file you want to output and voila! It's a done deal.

/john
Post #1477780
Posted Friday, July 26, 2013 12:53 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
jk_in_San_Diego (7/25/2013)
File this under "you learn something new every day" - my coworker (Linda Knott - The Magnificent!) reminded me that the Save button during the file name prompt has a down-arrow. Clicking the down-arrow allows you to select "Save with encoding..." which allows you to choose Unicode (the default), ANSI (which is ASCII), or Chineese characters.

Huzza! Select the correct encoding for the type of file you want to output and voila! It's a done deal.

/john


That's good to know. Thanks for posting back.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1477876
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse