Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CREATE TYPE + COLLATE

Posted on 2014-11-13
5
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:TONY TAYLOR
TONY TAYLOR earned 1200 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 66

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 70

Accepted Solution

by:
Scott Pletcher earned 800 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 66

Author Closing Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

721 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