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)
 Retrieving a piece of data

Author  Topic 

Swede
Yak Posting Veteran

74 Posts

Posted - 2002-02-12 : 09:02:41
If I only want to retrieve a piece of data, for example 50 characters of a text field, can I do that with a SELECT statement?

Is there a similar command like in VBScript Left(value, ##)?

=====================================
Why not try and do the impossible?

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-02-12 : 09:05:33
would you believe 'left'

select left(firstname,10) from validuser
will return the 1st 10 characters field called firstname.


ps...by text, i take it you mean a field not saved/read using the writetext/readtext commands.

Go to Top of Page

Swede
Yak Posting Veteran

74 Posts

Posted - 2002-02-12 : 09:08:31
just meant any field really :)

hehe thanks though.... left... well ill be damned lol

=====================================
Why not try and do the impossible?
Go to Top of Page

Swede
Yak Posting Veteran

74 Posts

Posted - 2002-02-12 : 09:12:08
yeah alright, seems you cannot:
"Argument data type text is invalid for argument 1 of left function."

Crap! :( Any solution? I am doing this in a stored procedure

=====================================
Why not try and do the impossible?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-12 : 09:45:09
SubString might work on text columns:

SELECT SubString(textCol, 1, 50) FROM myTable

I tested this in SQL 2000 and it works. I think if you stay within the 8,000 character limit, many string functions will work on text columns as well.

Go to Top of Page

Swede
Yak Posting Veteran

74 Posts

Posted - 2002-02-13 : 04:11:25
Neither worked.

=====================================
Why not try and do the impossible?
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-02-13 : 04:45:13
what if you do it in 2 stages....?

declare @abc varchar(50)
declare @def varchar(50)
select @abc = firstname from validuser
select @def = left(@abc,5)
print @def


(or the equivalent code that is used to access TEXT-type columns)

Go to Top of Page
   

- Advertisement -