<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>T-SQL.co.uk - Recent questions and answers</title>
<link>https://www.t-sql.co.uk/qa</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>Answered: 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?show=33#a33</link>
<description>

&lt;p&gt;
	This should do the trick: 
&lt;/p&gt;


&lt;p&gt;
	&lt;code&gt;
&lt;br&gt;SELECT * FROM 
&lt;br&gt;( SELECT ID , [VERSION] , NAME , deleted, 
&lt;br&gt;ROW_NUMBER() OVER ( PARTITION BY ID ORDER BY [VERSION] DESC ) AS rown , [DOCUMENT] 
&lt;br&gt;FROM dbo.SOURCEDOCUMENTS ) x WHERE rown = 1 
&lt;br&gt;AND convert(varchar(max),convert(varbinary(max),[DOCUMENT])) LIKE &#039;%something%&#039;
&lt;br&gt;
&lt;br&gt;&lt;/code&gt;
&lt;br&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?show=33#a33</guid>
<pubDate>Fri, 19 Aug 2022 13:17:57 +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>Answered: Select Block Mode of Text</title>
<link>https://www.t-sql.co.uk/23/select-block-mode-of-text?show=24#a24</link>
<description>

&lt;p&gt;
	&lt;span style=&quot;color: rgb(54, 59, 63); font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;There maybe addons out there, however the feature already exists:&lt;/span&gt;
&lt;br&gt;
&lt;/p&gt;


&lt;p&gt;
	&lt;span style=&quot;color: rgb(54, 59, 63); font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;
&lt;br&gt;&lt;/span&gt;
&lt;/p&gt;


&lt;p style=&quot;margin-bottom: 1.5rem; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; color: rgb(54, 59, 63); box-sizing: border-box; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;
	 To use this, you need to hit the ALT key on the keyboard and hold then by selecting the area you need with your mouse, we can select a region in block mode. 
&lt;br&gt;
&lt;/p&gt;


&lt;p style=&quot;margin-bottom: 1.5rem; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; color: rgb(54, 59, 63); box-sizing: border-box; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;
	Interestingly , you can then also Type in Block Mode too.....
&lt;/p&gt;


&lt;p style=&quot;margin-bottom: 1.5rem; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; color: rgb(54, 59, 63); box-sizing: border-box; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;
	Give it a try.
&lt;br&gt;
&lt;/p&gt;


&lt;p style=&quot;margin-bottom: 1.5rem; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 14px; color: rgb(54, 59, 63); box-sizing: border-box; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;
	&lt;img alt=&quot;image&quot; src=&quot;https://www.t-sql.co.uk/?qa=blob&amp;amp;qa_blobid=14305652782444465831&quot;&gt; 
&lt;br&gt;
&lt;/p&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/23/select-block-mode-of-text?show=24#a24</guid>
<pubDate>Tue, 19 May 2020 12:04:54 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=22#a22</link>
<description>

&lt;p style=&quot;box-sizing: inherit; margin-bottom: 1.25rem; font-family: &amp;quot;helvetica neue&amp;quot;, Helvetica, Roboto, Arial, sans-serif; font-size: 16px; line-height: 1.6; text-rendering: optimizelegibility; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255);&quot;&gt;
	If you want to get a list of all valid date and time formats, you could use the code below and change the @date to GETDATE() or any other date you want to use.  This will output just the valid formats.
&lt;/p&gt;


&lt;div style=&quot;box-sizing: inherit; margin: 0px 0px 20px; padding: 4px; width: 911px; background-color: rgb(255, 255, 225); border: 1px solid rgb(170, 170, 170); border-spacing: 5px; border-collapse: separate; font-family: &amp;quot;courier new&amp;quot;, Courier, monospace; font-size: 9pt; overflow: auto; color: rgb(34, 34, 34);&quot; class=&quot;codediv&quot;&gt;
	

&lt;pre style=&quot;box-sizing: inherit; margin-top: 0px; margin-bottom: 0px; padding: 2px; border: 0px solid rgb(136, 136, 136); min-height: 35px; height: auto;&quot; class=&quot;prettyprint lang-sql prettyprinted&quot;&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @date &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;DATETIME&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: red;&quot; class=&quot;str&quot;&gt;&#039;2006-12-30 00:38:54.840&#039;&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; #dateFormats &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;dateFormatOption &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; dateOutput &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;WHILE&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;@counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
   &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; TRY
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; #dateFormats
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(255, 0, 255);&quot; class=&quot;kwd2&quot;&gt;CONVERT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;),&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(255, 0, 255);&quot; class=&quot;kwd2&quot;&gt;CONVERT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;typ&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;@date&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; 
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
   &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; TRY
   &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; CATCH&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; @counter &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: gray;&quot; class=&quot;pun&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;lit&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
         &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;BREAK&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;
   &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; CATCH
&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 255);&quot; class=&quot;kwd&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: rgb(0, 0, 0);&quot; class=&quot;pln&quot;&gt; #dateFormats&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/17/how-do-i-change-date-and-time-conversions-type?show=22#a22</guid>
<pubDate>Wed, 26 Feb 2020 18:49:37 +0000</pubDate>
</item>
<item>
<title>Answered: What are SQL constraints?</title>
<link>https://www.t-sql.co.uk/15/what-are-sql-constraints?show=16#a16</link>
<description>Constraints are statements used to establish the rules for all records in the table. &lt;br /&gt;
&lt;br /&gt;
If any action violates a constraint, that action will be aborted. Constraints are defined while creating the database itself with CREATE TABLE statement, or after the table is created, by using ALTER TABLE statement. &lt;br /&gt;
&lt;br /&gt;
The five major constraints used in SQL are:&lt;br /&gt;
&lt;br /&gt;
NOT NULL: indicates that the column is required to have some value; it cannot be left null&lt;br /&gt;
&lt;br /&gt;
UNIQUE: ensures that each row and column has unique value; no value is being repeated in any other row or column&lt;br /&gt;
&lt;br /&gt;
PRIMARY KEY: used in association with NOT NULL and UNIQUE constraints to identify a particular unique record&lt;br /&gt;
&lt;br /&gt;
FOREIGN KEY: used to ensure the referential integrity of data in the table and also matches the value in one table with another using PRIMARY KEY&lt;br /&gt;
&lt;br /&gt;
CHECK: used to ensure the value in columns obeys specified conditions</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/15/what-are-sql-constraints?show=16#a16</guid>
<pubDate>Wed, 26 Feb 2020 15:41:41 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=14#a14</link>
<description>A JOIN is a keyword used to retrieve data from multiple tables based upon the relationship between the fields of the tables and present the results as a single set. The various types of JOINs commonly include INNER JOIN, OUTER JOIN, LEFT JOIN and RIGHT JOIN.</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/13/what-are-joins-in-sql-and-what-types-of-joins-are-there?show=14#a14</guid>
<pubDate>Wed, 26 Feb 2020 15:40:24 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=12#a12</link>
<description>An SQL clause is defined for the purpose of limiting the queried results to certain specified conditions.&lt;br /&gt;
&lt;br /&gt;
GROUP BY: used in aggregation to arrange identical data into groups, the GROUP BY clause follows the WHERE clause in a SELECT statement and is followed by the ORDER BY clause&lt;br /&gt;
&lt;br /&gt;
HAVING: used to specify a search condition in a GROUP BY clause, HAVING can be used in the absence of a GROUP BY clause by using a WHERE clause&lt;br /&gt;
&lt;br /&gt;
ORDER BY: sorts the result set in ascending (default) or descending (using DESC keyword) order&lt;br /&gt;
&lt;br /&gt;
WHERE: used to define the condition of the records to be extracted</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/11/what-are-the-different-clauses-used-in-sql?show=12#a12</guid>
<pubDate>Wed, 26 Feb 2020 15:38:51 +0000</pubDate>
</item>
<item>
<title>Answered: What are tables in SQL?</title>
<link>https://www.t-sql.co.uk/9/what-are-tables-in-sql?show=10#a10</link>
<description>The table is a collection of records organized into a set of rows and columns to form a model. There are no precise upper limits to the number of records that can be defined by rows in the table.</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/9/what-are-tables-in-sql?show=10#a10</guid>
<pubDate>Wed, 26 Feb 2020 15:38:06 +0000</pubDate>
</item>
<item>
<title>Answered: What is a DBMS?</title>
<link>https://www.t-sql.co.uk/7/what-is-a-dbms?show=8#a8</link>
<description>DBMS stands for database management system, which is a program used to help maintain, monitor, create, deploy and control use of a database. It also acts as a file manager for the data kept in a database, no matter the size or complexity of the database</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/7/what-is-a-dbms?show=8#a8</guid>
<pubDate>Wed, 26 Feb 2020 15:37:21 +0000</pubDate>
</item>
<item>
<title>Answered: What is SQL?</title>
<link>https://www.t-sql.co.uk/5/what-is-sql?show=6#a6</link>
<description>Structured Query Language is an American National Standards Institute database language used as a communication tool to create and access databases. SQL supports software applications by performing tasks such as retrieving, updating, inserting and deleting data. SQL makes it possible to execute queries, insert and update records, create and delete databases and tables, and more.</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/5/what-is-sql?show=6#a6</guid>
<pubDate>Wed, 26 Feb 2020 15:33:50 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=4#a4</link>
<description>You can rollback data after using delete statement</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/3/what-the-difference-between-delete-and-truncate-statements?show=4#a4</guid>
<pubDate>Wed, 26 Feb 2020 15:28:31 +0000</pubDate>
</item>
<item>
<title>Answered: 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?show=2#a2</link>
<description>-- Replace @date below with the date Value you want to convert&lt;br /&gt;
SELECT DATENAME(weekday, @Date) + &amp;#039; &amp;#039; + CASE WHEN DAY(@Date) in (1,21,31) &lt;br /&gt;
THEN convert(varchar,DAY(@Date)) + &amp;#039;st&amp;#039;&lt;br /&gt;
WHEN DAY(@Date) IN (2,22) then convert(varchar,DAY(@Date)) + &amp;#039;nd&amp;#039;&lt;br /&gt;
WHEN DAY(@Date) IN (3,23) then convert(varchar,DAY(@Date)) + &amp;#039;rd&amp;#039; &lt;br /&gt;
ELSE convert(varchar,DAY(@Date)) + &amp;#039;th &amp;#039; end +&lt;br /&gt;
DATENAME(month, @Date) &amp;nbsp;+ &amp;#039; &amp;#039; + convert(varchar,year(@Date)) as [English Suffix Date]</description>
<guid isPermaLink="true">https://www.t-sql.co.uk/1/how-can-i-get-the-date-in-sql-with-english-suffix-eg-21st?show=2#a2</guid>
<pubDate>Wed, 19 Feb 2020 11:56:30 +0000</pubDate>
</item>
</channel>
</rss>