Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TRANSFORM() in SQL SERVER
Message
 
 
À
17/11/2003 22:02:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00850850
Message ID:
00850852
Vues:
18
>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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform