Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

right aligned data Expand / Collapse
Author
Message
Posted Tuesday, December 3, 2002 1:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, October 25, 2004 4:10 AM
Points: 18, Visits: 1
hi,
my query is:
SELECT CAST(OID AS varchar(15)) ...........................
this is a possible result:

123456789012345
345____________
45_____________
4435666565656__

but I want right aligned data:

123456789012345
____________345
_____________45
__4435666565656

it's possible with a query ?

Thanks, anakin




Post #8541
Posted Tuesday, December 3, 2002 1:22 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, June 19, 2014 2:58 AM
Points: 2,642, Visits: 31
You can't do it easily. Something like this will give the desired result.


SELECT SPACE(15 - len(cast(OID AS varchar(15)))) + cast(OID as varchar(15))



Post #48344
Posted Tuesday, December 3, 2002 1:43 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, June 27, 2014 1:32 PM
Points: 1,104, Visits: 332
Hi,

Where do you want right aligned data - on a report, on screen? The above approach will only work if you are using a proportional font.

Regards,
Andy Jones



Regards,
Andy Jones
Post #48345
Posted Tuesday, December 3, 2002 3:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, October 25, 2004 4:10 AM
Points: 18, Visits: 1
no, I don't show data, the problem arise because I must order data by a calcutated text field.
My calculated text field si the concatenation of two fields, the second field is allways my numerical OID field, the first field is a variable datatype field.
When the first field is of type string it's ok, but is of type int I must include some blank otherwise the order is wrong.




Post #48346
Posted Tuesday, December 3, 2002 3:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:18 AM
Points: 7,051, Visits: 6,807
Try

STR(OID,15,0)






Far away is close at hand in the images of elsewhere.

Anon.

Post #48347
Posted Tuesday, December 3, 2002 4:48 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: Moderators
Last Login: Tuesday, April 22, 2014 1:22 PM
Points: 8,369, Visits: 734
I second for Davids suggestion. Of the most used options it is the easiest to read, and least code to write.




Post #48348
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse