You are here: Re: Programming Field Lengths « MsSQL Server « IT news, forums, messages
Re: Programming Field Lengths

Posted by Erland Sommarskog on 10/01/68 11:19

(bozzzza@lycos.co.uk) writes:
> Is it possible to tell sql server to cast to a datatype and set the
> field length to a variable.
>
> e.g. :-
>
> declare @flen int
> set @flen = 10
>
> select (cast somefield as char(@flen) newfield)
> into newtable
> from sometable
>
> I have also tried :-
> select (cast somefield as char(max(len(somefield))) newfield)
> into newtable
> from sometable
>
> When I try the above examples I get error in @flen; error in max
> respectivly.

No, you would have to use dynamic SQL for that. Seems easier to use
varchar.

What do you want to achieve, really?


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация