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 2005 Forums
 Transact-SQL (2005)
 How to restrict size

Author  Topic 

moramoga
Starting Member

34 Posts

Posted - 2008-01-23 : 16:08:04
Hi again,

For example I have this query:

Select error_Description from ErrorTable

Lets suppose that query return 200 characters, how do I restrict it, so it only returns 50 characters or letters?

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-01-23 : 16:17:09
LEFT(error_Description, 50)
Go to Top of Page

hey001us
Posting Yak Master

185 Posts

Posted - 2008-01-23 : 16:19:33
There is a 3 way as per my knowledge. you can use either one

Select substring(error_Description,1,50) from ErrorTable

Select left(error_Description,50) from ErrorTable

Select right(error_Description,50) from ErrorTable

hey
Go to Top of Page

moramoga
Starting Member

34 Posts

Posted - 2008-01-23 : 16:48:32
Thank you guys
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-01-23 : 17:03:17
For what it is worth you could also CAST the column:
DECLARE @Foo VARCHAR(10)

SET @Foo = '1234567890'

SELECT CAST(@Foo AS VARCHAR(5))
Go to Top of Page
   

- Advertisement -