home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!mtxinu!sybase!robert
- From: robert@sybase.com (Robert Garvey)
- Newsgroups: comp.databases.sybase
- Subject: Re: Right Justify Char strings
- Keywords: right justification, char data, functions
- Message-ID: <28249@sybase.sybase.com>
- Date: 19 Jan 93 23:19:26 GMT
- References: <Dave_Wetzel-140193110749@dwetzel.mis.stratus.com>
- Sender: news@Sybase.COM
- Organization: The Upstate Sadistics
- Lines: 41
-
- In article <Dave_Wetzel-140193110749@dwetzel.mis.stratus.com>, Dave_Wetzel@vos.stratus.com (David Wetzel) writes:
- |> Okay, it may be brain-damage, but can anyone tell me how to right justify a
- |> character string with Sybase (4.8). There's got to be an easy way,
- |> right??
-
- There is a way. Its ease is a matter of opinion. Using the functions
- that are part of Transact-SQL will allow you to do it, like this:
-
- 1> SELECT
- 2> col1 = CONVERT( varchar(8),
- 3> REPLICATE(" ", COL_LENGTH("test", "col1") - DATALENGTH(col1))
- 4> + col1 ),
- 5> col2 = convert( varchar(8),
- 6> REPLICATE(" ", COL_LENGTH("test", "col2") - DATALENGTH(RTRIM(col2)))
- 7> + rtrim(col2) )
- 8> FROM test
- 9> go
-
- col1 col2
- -------- --------
- 1 1
- 22 22
- 333 333
- 4444 4444
- 55555 55555
- 666666 666666
- 7777777 7777777
- 88888888 88888888
-
- (8 rows affected)
-
- Both col1 and col2 are eight character columns. The col1 column is
- varchar(8). The rtrim string function is needed for col2 because it is
- char(8), so every value is the full eight characters. There are
- probably other ways to accomplish this same result.
-
- --
- Robert Garvey robert@sybase.com {sun,lll-tis,pyramid,pacbell}!sybase!robert
- Sybase, Inc 6475 Christie Ave Emeryville, CA 94608-1010
-
- If Sybase were to pay employees for their opinions, they couldn't afford me.
-