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

Converting Integer to Text Expand / Collapse
Author
Message
Posted Tuesday, May 13, 2008 4:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 29, 2011 11:41 PM
Points: 8, Visits: 58
Hi,
I am trying to convert an integer to text in a query using:

CASE WHEN [Extension]<'80' THEN '0' + CAST( Extension AS text(12)) ELSE [Extension] END AS Extn

but I get the following error:
'Explicit conversion from data type int to text is not allowed'

Any suggestions? I dont want to convert the Table
Post #499441
Posted Tuesday, May 13, 2008 5:07 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, May 29, 2012 11:22 AM
Points: 1,755, Visits: 4,652
Use varchar rather than text?


Ryan Randall

Solutions are easy. Understanding the problem, now, that's the hard part.
Post #499450
Posted Tuesday, May 13, 2008 5:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 29, 2011 11:41 PM
Points: 8, Visits: 58
Hi,

The '0' is not added when I use varchar
Post #499454
Posted Tuesday, May 13, 2008 5:19 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, January 4, 2010 9:34 PM
Points: 387, Visits: 64
hi
Try this

CASE WHEN [Extension]<'80' THEN '0' + CAST( Extension AS varchar(12)) ELSE [Extension] END AS Extn

Post #499457
Posted Tuesday, May 13, 2008 5:23 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 20, 2014 5:23 PM
Points: 4,576, Visits: 8,341
It must be [Extension]<80, not [Extension]<'80' .
Post #499460
Posted Tuesday, May 13, 2008 5:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 29, 2011 11:41 PM
Points: 8, Visits: 58
Still no luck
Post #499463
Posted Tuesday, May 13, 2008 5:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, January 4, 2010 9:34 PM
Points: 387, Visits: 64
Try This
CASE WHEN [Extension]<80 THEN '0'+ CAST(Extension as VARCHAR(12)) ELSE CAST(Extension as VARCHAR(12)) END AS Extn
Post #499477
Posted Tuesday, May 13, 2008 5:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 29, 2011 11:41 PM
Points: 8, Visits: 58
Thank you all it works
Post #499487
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse