Home
Products & services
Code Snippets
Staff profiles
SEO
Contact us
781.910.7727
SQL Safe (sql function)
SQL Server function to clean a field and replace quotes. Returns null if empty string, otherwise a quoted value.
CREATE FUNCTION [dbo].[sqlsafe](@s nvarchar(4000) = null) RETURNS nvarchar(4000) AS BEGIN DECLARE @MyOutput nvarchar(4000) IF (@s is null or @s = '') BEGIN SET @MyOutput ='NULL' END ELSE BEGIN SET @MyOutput ='''' + replace(@s, '''', '''''') + '''' END RETURN @MyOutput END