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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to Update length Automatically
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

4 Posts

Posted - 12/04/2012 :  07:13:53  Show Profile  Reply with Quote
Hi All,

From a table I am getting the length of character in a column. My query is below

SELECT b.[file_id],b.[lineno],b.fileContent, datalength(b.fileContent) Length1
FROM FileBascContent b join filebasic on filebasic.[file_id]=b.[file_id]
WHERE substring(b.fileContent,1,4)
not in('VOL1','HDR1','UHL1','UTL1','HDR2','EOF1','EOF2') and filebasic.[file_id]=347

I am getting the result 98, 97 and 100 which is fine for me.

Is there any way which will add space 2 or 3 and the length will be 100. Which I want is that all the length which are not 100, should be hundred.

Is there any way to do that?

Please help!

Niladri Sekhar Biswas

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 12/04/2012 :  07:26:18  Show Profile  Reply with Quote
If the data type of b.fileContent column is CHAR(100), then u can always get datalength(b.fileContent) = 100 and len(b.fileContent) is actual string length

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000