Solved

CREATE TYPE + COLLATE

Posted on 2014-11-13
5
178 Views
Last Modified: 2016-02-11
Hi Guys

I'm trying to execute the below in 2008R2, and receive an errmsg 'Incorrect syntax near the keyword 'COLLATE'.'
The msdn CREATE TYPE page references COLLATE, but doesn't give an example.  Does anyone know the fix?

CREATE TYPE SFID FROM nvarchar(18) 
COLLATE SQL_Latin1_General_CP1_CS_AS

Open in new window


I'm building an SSIS package where the source is salesforce.com data, and they have a table PK of nvarchar(18).   Plus, the target database I've inherited has these nvarchar(18) columns but with collations SQL_Latin1_General_CP1_CI_AS, SQL_Latin1_General_CP1_CS_AS, and Latin1_General_CS_AS, and I'm trying to standardize it.

Thanks in advance.
Jim
0
Comment
Question by:Jim Horn
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:TONY TAYLOR
TONY TAYLOR earned 300 total points
ID: 40440726
The COLLATE should be on the table definition, not on the column definition.  In the above you are referencing a type that is column based rather than table based.

You can build it as a table, but that is NOT what you are doing above.

Reference:
http://msdn.microsoft.com/en-us/library/ms175007.aspx
0
 
LVL 65

Author Comment

by:Jim Horn
ID: 40440797
Adding the collation on the column is not a problem (below code middle block)
ALTER TABLE FROMSF_OBJECT_ASSESSMENT
DROP CONSTRAINT PK_FROMSF_OBJECT_Assessment
GO

ALTER TABLE FROMSF_OBJECT_ASSESSMENT
ALTER COLUMN id nvarchar(18) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL 
GO

ALTER TABLE FROMSF_OBJECT_ASSESSMENT
ADD CONSTRAINT PK_FROMSF_OBJECT_Assessment PRIMARY KEY (id) 
GO

Open in new window

Problem is I can't add COLLATE to a TYPE.  (Unless that is not possible...)
0
 
LVL 5

Expert Comment

by:TONY TAYLOR
ID: 40440829
I agree Jim, but a step beyond that is that a TYPE can have a COLLATE if it is a TABLE TYPE...

CREATE TYPE dbo.MyTableType AS TABLE ( 
	MyVarChar varchar(50) COLLATE SQL_Latin1_General_CP1_CS_AS, 
	MyInt int 
) 

Open in new window


So ultimately, it is based on the TABLE and assigned to the COLUMN.

Why?  I have no idea, ask Microsoft!!  :)
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 200 total points
ID: 40443115
>> Problem is I can't add COLLATE to a TYPE.  (Unless that is not possible.) <<

Yep, it's not possible.  The syntax makes clear that COLLATE applies only for a TYPE of table, not for one on based on a base data type.
0
 
LVL 65

Author Closing Comment

by:Jim Horn
ID: 40443158
Got it.  Thanks guys.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
convert in derived column 7 27
Simple SQL query from two tables 13 53
optimize stored procedure 6 24
SQL Syntax: How to force case sensitive query? 2 24
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question