Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TRANSFORM() in SQL SERVER
Message
 
 
To
17/11/2003 22:02:57
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00850850
Message ID:
00850852
Views:
17
>Is there a TRANSFORM() like function in SQL server?
>
>For example, can you do something like this in SQL Server?
>
>TRANSFORM(phone,"@R (999) 999-9999")


Hi Bob,

No such luck. You'll have to use multiple T-SQL functions to get result.
SELECT 
	'(' + STUFF(STUFF( CAST(@phone AS varchar(16)), 4,0,')'), 8,0,'-') AS phonenum
It can be made into UDF.
-- Create scalar function (FN)
IF EXISTS (SELECT * 
	   FROM   sysobjects 
	   WHERE  name = N'FormatPhone')
	DROP FUNCTION FormatPhone
GO
CREATE FUNCTION FormatPhone 
	(@phone int)
RETURNS varchar(16)
AS
BEGIN
	RETURN '(' + STUFF(STUFF( CAST(@phone AS varchar(16)), 4,0,')'), 8,0,'-')
END
GO

SELECT dbo.FormatPhone(1112223333)
GO
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform