0

First of all I am using SQL Server 9.00.4035.00 which is SQL Server 2005 SP3.

I am using the below command to fetch the results from a view which fetches rows from a table which includes columns with either english or greek characters.

sqlcmd -W -S SERVER_NAME -d DATABASE_NAME -U USER_NAME -P PASSWORD -s "|" -Q "set nocount on; set ansi_warnings off;SELECT * from DATABASE.VIEW;" 

This command returns rows with english characters ok, but when it comes to greek characters I only get ??????

For example instead of

1110|20160907|ΓΙΩΡΓΟΣ

I am getting

1110|20160907|????????

I already tried the -f and -u options but none of them seems to work. Here is how I used them:

650001 is for UTF-8 according with this link

sqlcmd -W -S SERVER_NAME -d DATABASE_NAME -U USER_NAME -P PASSWORD -f 65001 -s "|" -Q "set nocount on; set ansi_warnings off;SELECT * from DATABASE.TABLE;" 

1253 is for greek accoring to this book

sqlcmd -W -S SERVER_NAME -d DATABASE_NAME -U USER_NAME -P PASSWORD -f 1253 -s "|" -Q "set nocount on; set ansi_warnings off;SELECT * from DATABASE.TABLE;" 

-u option

sqlcmd -W -S SERVER_NAME -d DATABASE_NAME -U USER_NAME -P PASSWORD -u -s "|" -Q "set nocount on; set ansi_warnings off;SELECT * from DATABASE.TABLE;" 
Community
  • 1
  • 1

1 Answers1

0

I found the solution. The problem was that I was selecting from a view.

So I had DATABASE.TABLE1 and a view DATABASE.VIEW1 which was selecting from TABLE1

If I was selecting from TABLE1, the data was coming as they should using -f 65001 If I was selecting from VIEW1, the data was coming as ???.

The problem was that in the VIEW1 I was casting the already VARCHAR field to VARCHAR. So for some reason when I was casting the VARCHAR to VARCHAR it was missing the Collation I guess.

  • collation shouldn't have been your issue unless you were on a linked server. Unicode should be stored as NVARCHAR instead, or NTEXT for older versions. – S3S Sep 09 '16 at 18:12