<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>T-SQL.co.uk - Hot questions</title>
<link>https://www.t-sql.co.uk/hot</link>
<description>Powered by Question2Answer</description>
<item>
<title>test questio test</title>
<link>https://www.t-sql.co.uk/38/test-questio-test</link>
<description>[Application Status]&lt;br /&gt;
&lt;br /&gt;
      ,[BISnumber]&lt;br /&gt;
&lt;br /&gt;
      ,[AccountNumber]&lt;br /&gt;
&lt;br /&gt;
      ,[Token]&lt;br /&gt;
&lt;br /&gt;
      ,[Status]&lt;br /&gt;
&lt;br /&gt;
      ,[FacilityTypeDescription]&lt;br /&gt;
&lt;br /&gt;
      ,[Key]&lt;br /&gt;
&lt;br /&gt;
      ,[Account_no]&lt;br /&gt;
&lt;br /&gt;
      ,[Account_type]&lt;br /&gt;
&lt;br /&gt;
      ,[Customer_no]&lt;br /&gt;
&lt;br /&gt;
      ,[EFS ACCOUNT KEY]&lt;br /&gt;
&lt;br /&gt;
      ,[Check]</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/38/test-questio-test</guid>
<pubDate>Wed, 18 Jun 2025 10:03:16 +0000</pubDate>
</item>
<item>
<title>Mask Numbers</title>
<link>https://www.t-sql.co.uk/37/mask-numbers</link>
<description>

&lt;div&gt;
	

&lt;div&gt;
		CREATE FUNCTION dbo.MaskCreditCardLike_12_18 (
	&lt;/div&gt;
	

&lt;div&gt;
		    @input NVARCHAR(MAX)
	&lt;/div&gt;
	

&lt;div&gt;
		)
	&lt;/div&gt;
	

&lt;div&gt;
		RETURNS NVARCHAR(MAX)
	&lt;/div&gt;
	

&lt;div&gt;
		AS
	&lt;/div&gt;
	

&lt;div&gt;
		BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @output NVARCHAR(MAX) = @input;
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @i INT = 1;
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @digitCount INT = 0;
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @startPos INT = 0;
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		    WHILE @i &amp;lt;= LEN(@input)
	&lt;/div&gt;
	

&lt;div&gt;
		    BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		        DECLARE @c NCHAR(1) = SUBSTRING(@input, @i, 1);
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		        IF @c LIKE &#039;[0-9]&#039;
	&lt;/div&gt;
	

&lt;div&gt;
		        BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		            IF @digitCount = 0
	&lt;/div&gt;
	

&lt;div&gt;
		                SET @startPos = @i;
	&lt;/div&gt;
	

&lt;div&gt;
		            SET @digitCount += 1;
	&lt;/div&gt;
	

&lt;div&gt;
		        END
	&lt;/div&gt;
	

&lt;div&gt;
		        ELSE IF @c IN (&#039;-&#039;, &#039;/&#039;, &#039;*&#039;, &#039;X&#039;, &#039;x&#039;, &#039; &#039;)
	&lt;/div&gt;
	

&lt;div&gt;
		        BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		            -- allowed separator, do not reset
	&lt;/div&gt;
	

&lt;div&gt;
		            CONTINUE;
	&lt;/div&gt;
	

&lt;div&gt;
		        END
	&lt;/div&gt;
	

&lt;div&gt;
		        ELSE
	&lt;/div&gt;
	

&lt;div&gt;
		        BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		            -- invalid char, reset
	&lt;/div&gt;
	

&lt;div&gt;
		            SET @digitCount = 0;
	&lt;/div&gt;
	

&lt;div&gt;
		            SET @startPos = 0;
	&lt;/div&gt;
	

&lt;div&gt;
		        END
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		        -- Once we hit a 12- to 18-digit count, replace the original segment
	&lt;/div&gt;
	

&lt;div&gt;
		        IF @digitCount BETWEEN 12 AND 18
	&lt;/div&gt;
	

&lt;div&gt;
		        BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		            -- Now find the end of the segment
	&lt;/div&gt;
	

&lt;div&gt;
		            DECLARE @endPos INT = @i;
	&lt;/div&gt;
	

&lt;div&gt;
		            WHILE @endPos + 1 &amp;lt;= LEN(@input) AND 
	&lt;/div&gt;
	

&lt;div&gt;
		                  SUBSTRING(@input, @endPos + 1, 1) IN (&#039;0&#039;,&#039;1&#039;,&#039;2&#039;,&#039;3&#039;,&#039;4&#039;,&#039;5&#039;,&#039;6&#039;,&#039;7&#039;,&#039;8&#039;,&#039;9&#039;,&#039;-&#039;,&#039;/&#039;,&#039;*&#039;,&#039;X&#039;,&#039;x&#039;,&#039; &#039;)
	&lt;/div&gt;
	

&lt;div&gt;
		            BEGIN
	&lt;/div&gt;
	

&lt;div&gt;
		                SET @endPos += 1;
	&lt;/div&gt;
	

&lt;div&gt;
		            END
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		            DECLARE @replaceLength INT = @endPos - @startPos + 1;
	&lt;/div&gt;
	

&lt;div&gt;
		            SET @output = STUFF(@output, @startPos, @replaceLength, &#039;$&#039;);
	&lt;/div&gt;
	

&lt;div&gt;
		            RETURN @output;
	&lt;/div&gt;
	

&lt;div&gt;
		        END
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		        SET @i += 1;
	&lt;/div&gt;
	

&lt;div&gt;
		    END
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		    RETURN @output;
	&lt;/div&gt;
	

&lt;div&gt;
		END;
	&lt;/div&gt;
	

&lt;div&gt;
		GO
	&lt;/div&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	CREATE FUNCTION dbo.ReplaceCodePattern ( 
&lt;/div&gt;


&lt;div&gt;
	    @input NVARCHAR(MAX) 
&lt;/div&gt;


&lt;div&gt;
	) 
&lt;/div&gt;


&lt;div&gt;
	RETURNS NVARCHAR(MAX) 
&lt;/div&gt;


&lt;div&gt;
	AS 
&lt;/div&gt;


&lt;div&gt;
	BEGIN 
&lt;/div&gt;


&lt;div&gt;
	    DECLARE @output NVARCHAR(MAX) = @input; 
&lt;/div&gt;


&lt;div&gt;
	    DECLARE @start INT; 
&lt;/div&gt;


&lt;div&gt;
	    DECLARE @length INT; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	    -- Try 499 
&lt;/div&gt;


&lt;div&gt;
	    SET @start = PATINDEX(&#039;%499%****%&#039;, @output); 
&lt;/div&gt;


&lt;div&gt;
	    IF @start &amp;gt; 0 
&lt;/div&gt;


&lt;div&gt;
	    BEGIN 
&lt;/div&gt;


&lt;div&gt;
	        SET @length = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
&lt;/div&gt;


&lt;div&gt;
	        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
&lt;/div&gt;


&lt;div&gt;
	    END 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	    -- Try 540 
&lt;/div&gt;


&lt;div&gt;
	    SET @start = PATINDEX(&#039;%540%****%&#039;, @output); 
&lt;/div&gt;


&lt;div&gt;
	    IF @start &amp;gt; 0 
&lt;/div&gt;


&lt;div&gt;
	    BEGIN 
&lt;/div&gt;


&lt;div&gt;
	        SET @length = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
&lt;/div&gt;


&lt;div&gt;
	        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
&lt;/div&gt;


&lt;div&gt;
	    END 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	    -- Try 543 
&lt;/div&gt;


&lt;div&gt;
	    SET @start = PATINDEX(&#039;%543%****%&#039;, @output); 
&lt;/div&gt;


&lt;div&gt;
	    IF @start &amp;gt; 0 
&lt;/div&gt;


&lt;div&gt;
	    BEGIN 
&lt;/div&gt;


&lt;div&gt;
	        SET @length = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
&lt;/div&gt;


&lt;div&gt;
	        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
&lt;/div&gt;


&lt;div&gt;
	    END 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	    RETURN @output; 
&lt;/div&gt;


&lt;div&gt;
	END; 
&lt;/div&gt;


&lt;div&gt;
	GO 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	

&lt;div&gt;
		CREATE FUNCTION dbo.ReplaceCodePattern_Exclude16Digit ( 
	&lt;/div&gt;
	

&lt;div&gt;
		    @input NVARCHAR(MAX) 
	&lt;/div&gt;
	

&lt;div&gt;
		) 
	&lt;/div&gt;
	

&lt;div&gt;
		RETURNS NVARCHAR(MAX) 
	&lt;/div&gt;
	

&lt;div&gt;
		AS 
	&lt;/div&gt;
	

&lt;div&gt;
		BEGIN 
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @output NVARCHAR(MAX) = @input; 
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @cleaned NVARCHAR(MAX); 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    -- Clean string: remove -, /, *, X, space 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @cleaned = REPLACE(@input, &#039;-&#039;, &#039;&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @cleaned = REPLACE(@cleaned, &#039;/&#039;, &#039;&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @cleaned = REPLACE(@cleaned, &#039;*&#039;, &#039;&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @cleaned = REPLACE(@cleaned, &#039;X&#039;, &#039;&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @cleaned = REPLACE(@cleaned, &#039; &#039;, &#039;&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    -- Check for any 16-digit numeric substring 
	&lt;/div&gt;
	

&lt;div&gt;
		    IF PATINDEX(&#039;%[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%&#039;, @cleaned) &amp;gt; 0 
	&lt;/div&gt;
	

&lt;div&gt;
		    BEGIN 
	&lt;/div&gt;
	

&lt;div&gt;
		        RETURN @input; -- skip replacement 
	&lt;/div&gt;
	

&lt;div&gt;
		    END 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    -- Attempt match on 499 
	&lt;/div&gt;
	

&lt;div&gt;
		    DECLARE @start INT = PATINDEX(&#039;%499%****%&#039;, @output); 
	&lt;/div&gt;
	

&lt;div&gt;
		    IF @start &amp;gt; 0 
	&lt;/div&gt;
	

&lt;div&gt;
		    BEGIN 
	&lt;/div&gt;
	

&lt;div&gt;
		        DECLARE @length INT = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
	&lt;/div&gt;
	

&lt;div&gt;
		        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    END 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    -- Attempt match on 540 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @start = PATINDEX(&#039;%540%****%&#039;, @output); 
	&lt;/div&gt;
	

&lt;div&gt;
		    IF @start &amp;gt; 0 
	&lt;/div&gt;
	

&lt;div&gt;
		    BEGIN 
	&lt;/div&gt;
	

&lt;div&gt;
		        SET @length = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
	&lt;/div&gt;
	

&lt;div&gt;
		        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    END 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    -- Attempt match on 543 
	&lt;/div&gt;
	

&lt;div&gt;
		    SET @start = PATINDEX(&#039;%543%****%&#039;, @output); 
	&lt;/div&gt;
	

&lt;div&gt;
		    IF @start &amp;gt; 0 
	&lt;/div&gt;
	

&lt;div&gt;
		    BEGIN 
	&lt;/div&gt;
	

&lt;div&gt;
		        SET @length = CHARINDEX(&#039;****&#039;, @output, @start) + 3 - @start + 1; 
	&lt;/div&gt;
	

&lt;div&gt;
		        RETURN STUFF(@output, @start, @length, &#039;$&#039;); 
	&lt;/div&gt;
	

&lt;div&gt;
		    END 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		    RETURN @output; 
	&lt;/div&gt;
	

&lt;div&gt;
		END; 
	&lt;/div&gt;
	

&lt;div&gt;
		GO 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
	

&lt;div&gt;
		

&lt;div&gt;
			CREATE FUNCTION dbo.MaskCreditCardLike ( 
		&lt;/div&gt;
		

&lt;div&gt;
			    @input NVARCHAR(MAX) 
		&lt;/div&gt;
		

&lt;div&gt;
			) 
		&lt;/div&gt;
		

&lt;div&gt;
			RETURNS NVARCHAR(MAX) 
		&lt;/div&gt;
		

&lt;div&gt;
			AS 
		&lt;/div&gt;
		

&lt;div&gt;
			BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			    DECLARE @output NVARCHAR(MAX) = @input; 
		&lt;/div&gt;
		

&lt;div&gt;
			    DECLARE @normalized NVARCHAR(MAX); 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			    -- Clean input to only digits 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@input, &#039;-&#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@normalized, &#039;/&#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@normalized, &#039;*&#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@normalized, &#039;X&#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@normalized, &#039;x&#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			    SET @normalized = REPLACE(@normalized, &#039; &#039;, &#039;&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			    -- If no 16-digit sequence exists, return original 
		&lt;/div&gt;
		

&lt;div&gt;
			    IF PATINDEX(&#039;%[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%&#039;, @normalized) = 0 
		&lt;/div&gt;
		

&lt;div&gt;
			        RETURN @input; 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			    -- Naive scan for the 16-digit run in original 
		&lt;/div&gt;
		

&lt;div&gt;
			    DECLARE @i INT = 1; 
		&lt;/div&gt;
		

&lt;div&gt;
			    DECLARE @countDigits INT = 0; 
		&lt;/div&gt;
		

&lt;div&gt;
			    DECLARE @startPos INT = 0; 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			    WHILE @i &amp;lt;= LEN(@input) 
		&lt;/div&gt;
		

&lt;div&gt;
			    BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			        IF SUBSTRING(@input, @i, 1) LIKE &#039;[0-9]&#039; 
		&lt;/div&gt;
		

&lt;div&gt;
			        BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			            SET @countDigits = @countDigits + 1; 
		&lt;/div&gt;
		

&lt;div&gt;
			            IF @countDigits = 16 
		&lt;/div&gt;
		

&lt;div&gt;
			            BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			                SET @startPos = @i - 15; 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			                -- Replace the range with a $ 
		&lt;/div&gt;
		

&lt;div&gt;
			                SET @output = STUFF(@output, @startPos, 16, &#039;$&#039;); 
		&lt;/div&gt;
		

&lt;div&gt;
			                RETURN @output; 
		&lt;/div&gt;
		

&lt;div&gt;
			            END 
		&lt;/div&gt;
		

&lt;div&gt;
			        END 
		&lt;/div&gt;
		

&lt;div&gt;
			        ELSE IF CHARINDEX(SUBSTRING(@input, @i, 1), &#039;-/*Xx &#039;) &amp;gt; 0 
		&lt;/div&gt;
		

&lt;div&gt;
			        BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			            -- allow formatting chars 
		&lt;/div&gt;
		

&lt;div&gt;
			            CONTINUE; 
		&lt;/div&gt;
		

&lt;div&gt;
			        END 
		&lt;/div&gt;
		

&lt;div&gt;
			        ELSE 
		&lt;/div&gt;
		

&lt;div&gt;
			        BEGIN 
		&lt;/div&gt;
		

&lt;div&gt;
			            -- reset if invalid char 
		&lt;/div&gt;
		

&lt;div&gt;
			            SET @countDigits = 0; 
		&lt;/div&gt;
		

&lt;div&gt;
			        END 
		&lt;/div&gt;
		

&lt;div&gt;
			        SET @i = @i + 1; 
		&lt;/div&gt;
		

&lt;div&gt;
			    END 
		&lt;/div&gt;
		

&lt;div&gt;
			
&lt;br&gt; 
		&lt;/div&gt;
		

&lt;div&gt;
			    RETURN @output; 
		&lt;/div&gt;
		

&lt;div&gt;
			END; 
		&lt;/div&gt;
		

&lt;div&gt;
			GO 
		&lt;/div&gt;
	&lt;/div&gt;
	

&lt;div&gt;
		
&lt;br&gt; 
	&lt;/div&gt;
&lt;/div&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/37/mask-numbers</guid>
<pubDate>Wed, 21 May 2025 00:26:42 +0000</pubDate>
</item>
<item>
<title>Get Only Numbers from String</title>
<link>https://www.t-sql.co.uk/36/get-only-numbers-from-string</link>
<description>

&lt;p&gt;
	
&lt;br&gt;
&lt;/p&gt;


&lt;p&gt;
	
&lt;br&gt;
&lt;/p&gt;


&lt;p&gt;
	CREATE FUNCTION dbo.fn_KeepOnlyNumbers (@input NVARCHAR(MAX))
&lt;/p&gt;


&lt;p&gt;
	RETURNS NVARCHAR(MAX)
&lt;/p&gt;


&lt;p&gt;
	AS
&lt;/p&gt;


&lt;p&gt;
	BEGIN
&lt;/p&gt;


&lt;p&gt;
	    WHILE PATINDEX(&#039;%[^0-9]%&#039;, @input) &amp;gt; 0
&lt;/p&gt;


&lt;p&gt;
	    BEGIN
&lt;/p&gt;


&lt;p&gt;
	        SET @input = STUFF(@input, PATINDEX(&#039;%[^0-9]%&#039;, @input), 1, &#039;&#039;)
&lt;/p&gt;


&lt;p&gt;
	    END
&lt;/p&gt;


&lt;p&gt;
	
&lt;br&gt;
&lt;/p&gt;


&lt;p&gt;
	    RETURN @input
&lt;/p&gt;


&lt;p&gt;
	END
&lt;/p&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	Usage:
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	SELECT dbo.fn_KeepOnlyNumbers(&#039;A1B2C-3D_4E!5F&#039;) AS OnlyNumbers
&lt;/div&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/36/get-only-numbers-from-string</guid>
<pubDate>Wed, 14 May 2025 09:48:35 +0000</pubDate>
</item>
<item>
<title>How do I check for CC Numbers</title>
<link>https://www.t-sql.co.uk/35/how-do-i-check-for-cc-numbers</link>
<description>

&lt;p&gt;
	CREATE FUNCTION dbo.fn_ValidateCreditCard
&lt;/p&gt;


&lt;p&gt;
	(
&lt;/p&gt;


&lt;p&gt;
	    @CardNumber VARCHAR(25)
&lt;/p&gt;


&lt;p&gt;
	)
&lt;/p&gt;


&lt;p&gt;
	RETURNS TABLE
&lt;/p&gt;


&lt;p&gt;
	AS
&lt;/p&gt;


&lt;p&gt;
	RETURN
&lt;/p&gt;


&lt;p&gt;
	WITH Cleaned AS (
&lt;/p&gt;


&lt;p&gt;
	    SELECT 
&lt;/p&gt;


&lt;p&gt;
	        REPLACE(REPLACE(@CardNumber, &#039; &#039;, &#039;&#039;), &#039;-&#039;, &#039;&#039;) AS CleanCard
&lt;/p&gt;


&lt;p&gt;
	),
&lt;/p&gt;


&lt;p&gt;
	LuhnCheck AS (
&lt;/p&gt;


&lt;p&gt;
	    SELECT 
&lt;/p&gt;


&lt;p&gt;
	        CleanCard,
&lt;/p&gt;


&lt;p&gt;
	        LEN(CleanCard) AS CardLength,
&lt;/p&gt;


&lt;p&gt;
	        REVERSE(CleanCard) AS ReversedCard
&lt;/p&gt;


&lt;p&gt;
	    FROM Cleaned
&lt;/p&gt;


&lt;p&gt;
	),
&lt;/p&gt;


&lt;p&gt;
	Calculated AS (
&lt;/p&gt;


&lt;p&gt;
	    SELECT 
&lt;/p&gt;


&lt;p&gt;
	        CleanCard,
&lt;/p&gt;


&lt;p&gt;
	        CardLength,
&lt;/p&gt;


&lt;p&gt;
	        SUM(
&lt;/p&gt;


&lt;p&gt;
	            CASE 
&lt;/p&gt;


&lt;p&gt;
	                WHEN Number % 2 = 0 THEN Digit
&lt;/p&gt;


&lt;p&gt;
	                ELSE 
&lt;/p&gt;


&lt;p&gt;
	                    CASE 
&lt;/p&gt;


&lt;p&gt;
	                        WHEN Digit * 2 &amp;gt; 9 THEN Digit * 2 - 9 
&lt;/p&gt;


&lt;p&gt;
	                        ELSE Digit * 2 
&lt;/p&gt;


&lt;p&gt;
	                    END
&lt;/p&gt;


&lt;p&gt;
	            END
&lt;/p&gt;


&lt;p&gt;
	        ) AS LuhnSum
&lt;/p&gt;


&lt;p&gt;
	    FROM (
&lt;/p&gt;


&lt;p&gt;
	        SELECT 
&lt;/p&gt;


&lt;p&gt;
	            CleanCard,
&lt;/p&gt;


&lt;p&gt;
	            CardLength,
&lt;/p&gt;


&lt;p&gt;
	            Digit = CAST(SUBSTRING(ReversedCard, Number + 1, 1) AS INT),
&lt;/p&gt;


&lt;p&gt;
	            Number
&lt;/p&gt;


&lt;p&gt;
	        FROM LuhnCheck
&lt;/p&gt;


&lt;p&gt;
	        JOIN master.dbo.spt_values ON type = &#039;P&#039; AND Number BETWEEN 0 AND LEN(ReversedCard) - 1
&lt;/p&gt;


&lt;p&gt;
	    ) AS Digits
&lt;/p&gt;


&lt;p&gt;
	    GROUP BY CleanCard, CardLength
&lt;/p&gt;


&lt;p&gt;
	),
&lt;/p&gt;


&lt;p&gt;
	IssuerCheck AS (
&lt;/p&gt;


&lt;p&gt;
	    SELECT 
&lt;/p&gt;


&lt;p&gt;
	        CleanCard,
&lt;/p&gt;


&lt;p&gt;
	        CardLength,
&lt;/p&gt;


&lt;p&gt;
	        CASE 
&lt;/p&gt;


&lt;p&gt;
	            WHEN CleanCard LIKE &#039;4%&#039; AND (CardLength = 13 OR CardLength = 16 OR CardLength = 19) THEN &#039;Visa&#039;
&lt;/p&gt;


&lt;p&gt;
	            WHEN CleanCard LIKE &#039;5[1-5]%&#039; AND CardLength = 16 THEN &#039;MasterCard&#039;
&lt;/p&gt;


&lt;p&gt;
	            WHEN CleanCard LIKE &#039;222[1-9]%&#039; OR CleanCard LIKE &#039;22[3-9][0-9]%&#039; 
&lt;/p&gt;


&lt;p&gt;
	                 OR CleanCard LIKE &#039;2[3-6][0-9][0-9]%&#039; OR CleanCard LIKE &#039;27[01][0-9]%&#039; 
&lt;/p&gt;


&lt;p&gt;
	                 OR CleanCard LIKE &#039;2720%&#039; AND CardLength = 16 THEN &#039;MasterCard&#039;
&lt;/p&gt;


&lt;p&gt;
	            WHEN CleanCard LIKE &#039;3[47]%&#039; AND CardLength = 15 THEN &#039;American Express&#039;
&lt;/p&gt;


&lt;p&gt;
	            WHEN CleanCard LIKE &#039;6011%&#039; OR CleanCard LIKE &#039;65%&#039; OR CleanCard LIKE &#039;64[4-9]%&#039; 
&lt;/p&gt;


&lt;p&gt;
	                 AND CardLength = 16 THEN &#039;Discover&#039;
&lt;/p&gt;


&lt;p&gt;
	            ELSE &#039;Unknown&#039;
&lt;/p&gt;


&lt;p&gt;
	        END AS Issuer
&lt;/p&gt;


&lt;p&gt;
	    FROM Calculated
&lt;/p&gt;


&lt;p&gt;
	),
&lt;/p&gt;


&lt;p&gt;
	Final AS (
&lt;/p&gt;


&lt;p&gt;
	    SELECT 
&lt;/p&gt;


&lt;p&gt;
	        c.CleanCard AS CardNumber,
&lt;/p&gt;


&lt;p&gt;
	        i.Issuer,
&lt;/p&gt;


&lt;p&gt;
	        CASE WHEN c.LuhnSum % 10 = 0 THEN 1 ELSE 0 END AS IsValid
&lt;/p&gt;


&lt;p&gt;
	    FROM Calculated c
&lt;/p&gt;


&lt;p&gt;
	    JOIN IssuerCheck i ON c.CleanCard = i.CleanCard
&lt;/p&gt;


&lt;p&gt;
	)
&lt;/p&gt;


&lt;p&gt;
	SELECT * FROM Final;
&lt;/p&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	Example Usage: 
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt; 
&lt;/div&gt;


&lt;div&gt;
	

&lt;div&gt;
		SELECT dbo.fn_IsValidCreditCardNumber(&#039;4539 1488 0343 6467&#039;) AS IsValid; -- Returns 1 
	&lt;/div&gt;
	

&lt;div&gt;
		SELECT dbo.fn_IsValidCreditCardNumber(&#039;1234 5678 9012 3456&#039;) AS IsValid; -- Returns 0 
	&lt;/div&gt;
&lt;/div&gt;


&lt;div&gt;
	
&lt;br&gt;
&lt;/div&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/35/how-do-i-check-for-cc-numbers</guid>
<pubDate>Wed, 14 May 2025 08:47:00 +0000</pubDate>
</item>
<item>
<title>I have rtf text converted to blob stored in a SQL field, and I need to search the text content of it.</title>
<link>https://www.t-sql.co.uk/32/have-text-converted-blob-stored-field-need-search-text-content</link>
<description>

&lt;p&gt;
	&lt;span style=&quot;color: rgb(35, 38, 41); font-family: -apple-system, BlinkMacSystemFont,&quot;&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255);&quot;&gt;I have loads of .rtf files, which are stored in a SQL blob, in a field/Column in my database. &lt;/span&gt;&lt;/span&gt; 
&lt;/p&gt;


&lt;p&gt;
	&lt;span style=&quot;color: rgb(35, 38, 41); font-family: -apple-system, BlinkMacSystemFont,&quot;&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255);&quot;&gt;
&lt;br&gt;&lt;/span&gt;&lt;/span&gt; 
&lt;/p&gt;


&lt;p&gt;
	&lt;span style=&quot;color: rgb(35, 38, 41); font-family: -apple-system, BlinkMacSystemFont,&quot;&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255);&quot;&gt;How can I search for text within this document without converting all docs back in to their respective .rtf format.&lt;/span&gt;&lt;/span&gt; 
&lt;/p&gt;


&lt;p&gt;
	&lt;span style=&quot;color: rgb(35, 38, 41); font-family: -apple-system, BlinkMacSystemFont,&quot;&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255);&quot;&gt;
&lt;br&gt;&lt;/span&gt;&lt;/span&gt; 
&lt;/p&gt;


&lt;p&gt;
	&lt;span style=&quot;color: rgb(35, 38, 41); font-family: -apple-system, BlinkMacSystemFont,&quot;&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255);&quot;&gt;
&lt;br&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/32/have-text-converted-blob-stored-field-need-search-text-content</guid>
<pubDate>Fri, 19 Aug 2022 12:56:26 +0000</pubDate>
</item>
<item>
<title>How Should I Store Currency Values in SQL Server?</title>
<link>https://www.t-sql.co.uk/26/how-should-i-store-currency-values-in-sql-server</link>
<description>

&lt;div style=&quot;&quot; data-widget-announcement-bar=&quot;&quot; data-th-widget=&quot;announcementBar&quot; data-th-element-name=&quot;announcementBar1&quot; class=&quot;&quot;&gt;
	

&lt;div style=&quot;&quot; class=&quot;&quot; id=&quot;acontainer&quot;&gt;
		
&lt;br&gt;
	&lt;/div&gt;
&lt;/div&gt;


&lt;div style=&quot;box-sizing: border-box; position: relative; min-height: 1px; padding-left: 15px; padding-right: 15px; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif;&quot; data-widget-article-content=&quot;&quot; data-th-widget=&quot;article.content&quot; data-th-element-name=&quot;articleContent4&quot; class=&quot;col-md-12 articleContent4 articleContent oUhbblYOaqbcblYOaqbcC ng-scope&quot;&gt;
	

&lt;div style=&quot;box-sizing: border-box; margin: 0px -15px; clear: both;&quot; class=&quot;articles-wrap ng-scope&quot;&gt;
		

&lt;div style=&quot;box-sizing: border-box; border: 1px solid rgb(230, 231, 233); margin-bottom: 20px; float: left; width: 424.118px; padding-top: 20px; padding-left: 10px;&quot; class=&quot;article-stream widget-top-border ng-scope&quot;&gt;
			

&lt;div style=&quot;box-sizing: border-box; padding: 0px 15px 20px 10px; line-height: 1.45; width: 412.123px; display: inline-block; margin-top: 0px;&quot; class=&quot;content&quot;&gt;
				

&lt;div style=&quot;font-size: 14px; background-color: rgb(255, 255, 255); box-sizing: border-box;&quot; class=&quot;ng-scope&quot;&gt;
					

&lt;div style=&quot;box-sizing: border-box; margin-top: 30px; overflow-wrap: break-word; color: rgb(34, 38, 53) !important; font-size: 19px !important; line-height: 1.45 !important; font-family: Cambria, serif !important;&quot; class=&quot;content-html&quot;&gt;
						

&lt;div style=&quot;box-sizing: border-box;&quot;&gt;
							

&lt;blockquote style=&quot;box-sizing: border-box; padding: 8px 25px 14px; margin: 25px auto; font-size: 16px; border-left: none; background-color: transparent; border-top-color: rgb(84, 84, 84); border-bottom-color: rgb(84, 84, 84); width: 387.123px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-weight: 600; line-height: 1.3; text-align: center;&quot;&gt;
								

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 5px; font-size: 14px;&quot;&gt;
									&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Never ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever store currency as a float in your database.&lt;/em&gt;
								&lt;/p&gt;
							&lt;/blockquote&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								I completely agree with this statement. Never store values used in financial calculations as floating point values, because a floating point is an approximate representation of a decimal value, stored as binary. In most cases it is inaccurate as soon as you store it. You can read more in this excellent - if a little dry - &lt;a style=&quot;box-sizing: border-box; background: transparent; color: rgb(41, 168, 255); text-decoration-line: none;&quot; rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html&quot;&gt;technical paper&lt;/a&gt;.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								With that out of the way, we get into an interesting discussion about the &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;correct&lt;/strong&gt; data type to store currency values.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								&lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;MONEY&lt;/code&gt; and &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;SMALLMONEY&lt;/code&gt;. I like to think I know a little bit about picking the right data type for a certain column.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								So I was surprised when a friend on that Twitter thread mentioned that he stores currency values as integers (multiplying them by 100 first). Being as literal as I am, I thought he meant the &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;INTEGER&lt;/code&gt; (or &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;INT&lt;/code&gt;) data type, which is a four-byte data type that goes up to around 2.1 billion (for values greater than zero), but Michael reminded me that &amp;quot;big integers exist,&amp;quot; so of course my friend was talking about &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;BIGINT&lt;/code&gt;.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								I wrote in a reply that &amp;quot;Decimal will have to do. I&#039;m not going to store money as a &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;BIGINT&lt;/code&gt;.&amp;quot; Nevertheless, I found it an interesting thought experiment to write about here.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								Assume that your currency has a hundred possible decimal values from 0.00 to 0.99. Now assume that you can eliminate pesky rounding errors by storing currency data in cents as a &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;BIGINT&lt;/code&gt;. This requires you to multiply the currency amount by 100 when inserting it, and dividing by 100 when displaying it. That seems counterproductive in my mind, but bear with me as we investigate this further.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								What problem is this meant to solve? Why avoid the use of the &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;DECIMAL&lt;/code&gt; data type, which is engineered to store decimal values with a decimal precision? Is the risk of rounding errors so great as to avoid a data type completely as the floating point? Surely &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;DECIMAL&lt;/code&gt; can handle this? Most of the time we use simple sums ( &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;SUM&lt;/code&gt;), averages ( &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;AVG&lt;/code&gt;), and regular arithmetic operations like addition, subtraction, multiplication and division, and in my experience - provided I put the parentheses in the right place - I&#039;ve never run into a rounding error that was significant enough (i.e. outside of the tolerance of the organization calculating the amounts) to be a problem.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								As I&#039;ve pointed out before, &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;BIGINT&lt;/code&gt; ranges from negative 9 quintillion, to positive 9 quintillion (a number that is 19 digits wide). That&#039;s a lot of squillions. Even storing these values as cents, you can store amounts that could handle even the ill-fated &lt;a style=&quot;box-sizing: border-box; background: transparent; color: rgb(41, 168, 255); text-decoration-line: none;&quot; rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Zimbabwean_dollar&quot;&gt;Zimbabwean dollar&lt;/a&gt;, which - at the time it was discontinued - was distributed in $100-trillion notes (100,000,000,000,000.00, or 17 digits wide). A &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;BIGINT&lt;/code&gt; needs 8 bytes of uncompressed storage for each value.
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								Now &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;DECIMAL&lt;/code&gt; is a different beastie. If you need the highest precision, a &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;DECIMAL&lt;/code&gt; can use up to 17 bytes for each value. Generally though, I like using &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;DECIMAL(19,4)&lt;/code&gt; for currency, which needs 9 bytes and can store numbers 19 digits wide, where the last four digits are after the decimal place. Coincidentally, this has the same range of values as the &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;MONEY&lt;/code&gt; data type. Maybe it&#039;s not a coincidence that I chose that then, eh?
							&lt;/p&gt;
							

&lt;p style=&quot;box-sizing: border-box; margin-top: 5px; margin-bottom: 15px; font-size: 14px;&quot;&gt;
								Purists will &lt;a style=&quot;box-sizing: border-box; background: transparent; color: rgb(41, 168, 255); text-decoration-line: none;&quot; rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/questions/582797&quot;&gt;say&lt;/a&gt; that the &lt;code style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; padding: 2px 4px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); white-space: nowrap; border-radius: 4px;&quot;&gt;MONEY&lt;/code&gt; data type is woefully inaccurate when it comes to calculations, including multiplication and division. To those purists I say &amp;quot;pish!&amp;quot; Unless we&#039;re talking Bitcoin, a currency amount usually has two decimal places. By using four decimal places, this means that rounding errors are less likely. In the vast majority of cases you will be doing things like summing values, calculating percentages,&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/26/how-should-i-store-currency-values-in-sql-server</guid>
<pubDate>Fri, 26 Jun 2020 08:24:48 +0000</pubDate>
</item>
<item>
<title>Select Block Mode of Text</title>
<link>https://www.t-sql.co.uk/23/select-block-mode-of-text</link>
<description>I want to be able to select from my SSMS window text in a block like in textpad. Is there an add on for this?</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/23/select-block-mode-of-text</guid>
<pubDate>Tue, 19 May 2020 11:54:03 +0000</pubDate>
</item>
<item>
<title>How Do I change Date and Time Conversions Type</title>
<link>https://www.t-sql.co.uk/17/how-do-i-change-date-and-time-conversions-type</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/17/how-do-i-change-date-and-time-conversions-type</guid>
<pubDate>Wed, 26 Feb 2020 16:11:11 +0000</pubDate>
</item>
<item>
<title>What are JOINs in SQL, and what types of JOINs are there?</title>
<link>https://www.t-sql.co.uk/13/what-are-joins-in-sql-and-what-types-of-joins-are-there</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/13/what-are-joins-in-sql-and-what-types-of-joins-are-there</guid>
<pubDate>Wed, 26 Feb 2020 15:40:11 +0000</pubDate>
</item>
<item>
<title>What is the difference between DELETE and TRUNCATE statements?</title>
<link>https://www.t-sql.co.uk/3/what-the-difference-between-delete-and-truncate-statements</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/3/what-the-difference-between-delete-and-truncate-statements</guid>
<pubDate>Wed, 26 Feb 2020 15:26:59 +0000</pubDate>
</item>
<item>
<title>What is SQL?</title>
<link>https://www.t-sql.co.uk/5/what-is-sql</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/5/what-is-sql</guid>
<pubDate>Wed, 26 Feb 2020 15:33:37 +0000</pubDate>
</item>
<item>
<title>What are SQL constraints?</title>
<link>https://www.t-sql.co.uk/15/what-are-sql-constraints</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/15/what-are-sql-constraints</guid>
<pubDate>Wed, 26 Feb 2020 15:41:19 +0000</pubDate>
</item>
<item>
<title>What is a DBMS?</title>
<link>https://www.t-sql.co.uk/7/what-is-a-dbms</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/7/what-is-a-dbms</guid>
<pubDate>Wed, 26 Feb 2020 15:37:10 +0000</pubDate>
</item>
<item>
<title>What are the different clauses used in SQL?</title>
<link>https://www.t-sql.co.uk/11/what-are-the-different-clauses-used-in-sql</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/11/what-are-the-different-clauses-used-in-sql</guid>
<pubDate>Wed, 26 Feb 2020 15:38:34 +0000</pubDate>
</item>
<item>
<title>What are tables in SQL?</title>
<link>https://www.t-sql.co.uk/9/what-are-tables-in-sql</link>
<description></description>
<guid isPermaLink="true">https://www.t-sql.co.uk/9/what-are-tables-in-sql</guid>
<pubDate>Wed, 26 Feb 2020 15:37:52 +0000</pubDate>
</item>
<item>
<title>How can I get the DATE in SQL with English Suffix Eg 21st</title>
<link>https://www.t-sql.co.uk/1/how-can-i-get-the-date-in-sql-with-english-suffix-eg-21st</link>
<description>I want to be able to pull back the DATE from SQL which displays in the format &amp;quot; Day Name Date Number + Suffix Month Year</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/1/how-can-i-get-the-date-in-sql-with-english-suffix-eg-21st</guid>
<pubDate>Wed, 19 Feb 2020 11:53:35 +0000</pubDate>
</item>
</channel>
</rss>