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 Statement in SQL

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi,

I want to format a column(avoid some leading zeros). Is there is format function in SQL query of SQL Server.

Urgent Help.

Thanks in advance

Sathya
 
I don't know of a format function. The closest thing is to use the string manipulation functions but it is ugly.
Suppose colWithLeadZeroes is the name of your column with leading zeros and that it is a CHAR or VARCHAR datatype.
Code:
SELECT SUBSTRING(colWithLeadZeroes, PATINDEX('%[^0]%', colWithLeadZeroes),DATALENGTH(colWithLeadZeroes))

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top