Solved

Determine the length of the longest string in a CSV file to figure out the optimal "x" for an NVARCHAR(x)

Posted on 2008-10-03
2
768 Views
Last Modified: 2013-11-25
Hi,

I want to know the best way to see, for each column in a CSV file, what the longest string is in the column. This way we can pick a number of characters that is 20% larger than this for a cushion. I know i could just use an nvarchar(max), but I think this is needlessly wasteful. I know I could do something like this in excel, but I think the best solution would be a little command/script I could run in Powershell or something.

Thanks!
0
Comment
Question by:Dicklestein
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 50 total points
ID: 22634961
The great thing about nvarchar fields is the VAR.  It's variable.  The actual space used is limited to the actual data on each row.  nvarchar(max) will also stay in the the page if possible.  Only if the data is too big to fit on a page will it not be stored with it.
0
 

Author Comment

by:Dicklestein
ID: 22636986
OK, I understand. Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 32
always on switch back after failover 2 35
Tsql query 6 22
MailAddress in vb 4 15
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

809 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