nvarchar datatypes

  • In a recent database design I used a lot of nvarchar data types. Everything was running fine until one day when I did a report from the system tables to document the tables, columns, datatypes and sizes and found that the size stored was 2 times the size I specified. This only occured on the nvarchar types.

    I rechecked my table design and saw that the size was still as I specifed. This is a problem when we use Crystal Reports to create reports because it pulls the size from the system tables so when we have a field with nvarchar 255 it sees it as a BLOB. When I look at the system tables it shows this field as size 510.

    What happened and how can I correct it?

  • The NVARCHAR data type is for Unicode character sets. If you don't need Unicode character set, use VARCHAR, which is single byte-wide character set as opposed to 2-byte wide character set. If you specify an NVARCHAR(100) field, the length is 100, but the actual storage size is 200 bytes (MAX, since it's variable length). To fix this, either alter the table design, or use stored procedures to generate a resultset and have Crystal use the resultset for its datasource. You can do a CONVERT(VARCHAR(200), NVarcharField) in the procedure to specify a different datatype on output. Using Crystal to query the database directly is a recipe for disaster anyway...

    Jay

  • Jay is right - NVarchar will be double the size. For example you can have a varchar(8000) but you can only have a nvarchar(4000).

    Create views for your Crystal Reports - and convert them to varchar whenever you can.

    Patrick

    Quand on parle du loup, on en voit la queue

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply