Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format function

Status
Not open for further replies.

storm197

MIS
Oct 9, 2002
55
CA
Hi,

In SQL, is there a Format function that allow me to do what i'm doing in Access with the following line :

Format(dbo_GPM_E_ELE.Fiche,"0000000")

It gives me 0000034 instead of 34.

When I type it, Format is blue as if SQL recognize it. But it tells me that Format is not a valid function.
 
I think CAST or CONVERT may be of use - Look them up in BOL.

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
FORMAT turns blue as its a reserved word used when backing up and restoring databases programmatically (i.e. using the BACKUP or RESTORE commands)

In order to format the field with leading spaces, you could do it in a couple of ways but I would do it using replicate
Code:
SELECT REPLICATE ( '0' , 7- len(dbo_GPM_E_ELE.Fiche))  + convert(varchar(10),dbo_GPM_E_ELE.Fiche)
[code]



"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top