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 2000 Forums
 Transact-SQL (2000)
 Select first 50 characters

Author  Topic 

rintus
Starting Member

26 Posts

Posted - 2008-10-01 : 19:40:08
I am trying to select the first 50 characters from a field. I tried the following SQL

Select name,
roll_no,
left(summary, 50) Summary
from student

Somehow it doesn't seem to work.

Please suggest.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-01 : 19:47:54
You can use LEFT or SUBSTRING to achieve this. I don't see an issue with what you have posted. When you say "it doesn't seem to work", could you elaborate? Are you getting an error? Incorrect results? ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-02 : 04:49:59
what is the datatype of Summary field?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-02 : 05:09:39
Maybe there are many spaces in the beginning of the column value?
Maybe there are many CR or LF in the beginning of the column value?

Select name,
roll_no,
LEFT(REPLACE(REPLACE(REPLACE(Summary, CHAR(13), ' '), CHAR(10), ' '), ' ', ' '), 50) Summary
from student


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-02 : 05:14:07
quote:
Originally posted by Peso

Maybe there are many spaces in the beginning of the column value?
Maybe there are many CR or LF in the beginning of the column value?

Select name,
roll_no,
LEFT(REPLACE(REPLACE(REPLACE(Summary, CHAR(13), ' '), CHAR(10), ' '), ' ', ' '), 50) Summary
from student


E 12°55'05.63"
N 56°04'39.26"



may be Summary is of text dadatype

Select name,
roll_no,
substring(summary,1,50) Summary
from student
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-02 : 05:19:10
There are many maybe's rigth now...



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-02 : 05:22:55
quote:
Originally posted by Peso

There are many maybe's rigth now...



E 12°55'05.63"
N 56°04'39.26"



Until OP comes back with what real problem is
Go to Top of Page

rintus
Starting Member

26 Posts

Posted - 2008-10-02 : 09:54:54
It working now. Thanks :)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-02 : 10:01:27
What was the problem?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

rintus
Starting Member

26 Posts

Posted - 2008-10-02 : 11:22:01
I was using DBVisualizer to run my queries and it was screwing up the results. When I use a different tool, it works fine. Thanks to all and sorry for the trouble.
Go to Top of Page
   

- Advertisement -