Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 question on field lengths

Author  Topic 

kowalsky
Starting Member

29 Posts

Posted - 2013-09-05 : 17:35:07
hi all,
i didn't think this thru', nevertheless, here is my question:
I have a table in a development database with nvarchar fields. Most of them are nvarchar(50). Later on, in the QA environment, a new copy of the database was created and the table has the same fields but the lengths have been modified to correspond to the actual lengths of the source data fields. Most of the time the lenghts are smaller. Is there any way I can insert the data from my development table into the QA table namely, a nvarchar(50) into a nvarchar(4), knowing that the actual length of that field is always 4.

Thanks,
kowalsky

kowalsky
Starting Member

29 Posts

Posted - 2013-09-05 : 17:47:48
I believe one way could be to have a conversion before the insert:
insert into tableQA(fld1, fld2)
select CONVERT(nvarchar(4), fld1) as fld1, CONVERT(nvarchar(10), fld2) as fld2 from tableDEV

Is there any other way?

Thanks,
kowalsky

kowalsky
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2013-09-06 : 01:26:15
You could just do the straight insert and SQL Server will about if you have longer data than will fit. Other than that, not really othe rthan select LEFT(fld1,4) type of thing.

Now go and fix your development database so it represents the actual database before you get into any more trouble ;) !!
Go to Top of Page
   

- Advertisement -