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
 SQL Server Development (2000)
 Can T-SQl do this?

Author  Topic 

p2bl
Yak Posting Veteran

54 Posts

Posted - 2001-11-30 : 08:05:38
Here is a table "table1" with a char(5) column "col1"
the value in col1 looks like this:
12345
23568
01235

the value of col consists of number
if I wanner get a char(5) result that every digit of this value
should be the max of the value of col at the same digit,how to?
I have thought this for about a week?Maybe it is a mission impossible?


I do not know what is what

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2001-11-30 : 08:17:28
Like this?

SELECT MAX(SUBSTRING(col1, 1, 1))
+ MAX(SUBSTRING(col1, 2, 1))
+ MAX(SUBSTRING(col1, 3, 1))
+ MAX(SUBSTRING(col1, 4, 1))
+ MAX(SUBSTRING(col1, 5, 1))
FROM table1



Go to Top of Page

izaltsman
A custom title

1139 Posts

Posted - 2001-11-30 : 08:30:01
If you have values that are less then 5 characters long and you want to treat them as right-aligned, replace col1 in Arnold's statement with

(REPLICATE(' ', 5-LEN(col1))+col1)

to pad the value with spaces.

Go to Top of Page

p2bl
Yak Posting Veteran

54 Posts

Posted - 2001-11-30 : 08:33:40
Ha ha.So simple!
I find myself a idiot!
Thanks a lot

I do not know what is what
Go to Top of Page
   

- Advertisement -