Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

T-SQL Min and Max

$
0
0

I am trying to get the min and max values from the results of the first part of my query:

SELECT DISTINCT    a.[Recording Date],     REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(        TRIM([Document Number]), '0','n'),'1','n'),'2','n'),'3','n'),'4','n'),'5','n'),'6','n'),'7','n'),'8','n'),'9','n') AS patternFROM     [TPEConversionTeam].[dbo].[KY_Shelby_Recorder_History] aWHERE     REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(        TRIM([Document Number]),'0','n'),'1','n'),'2','n'),'3','n'),'4','n'),'5','n'),'6','n'),'7','n'),'8','n'),'9','n') = 'nnnnnn-n'

Expected results should be 1993-01-06 and 2023-12-31:

enter image description here

But I'm getting everything back so looks like my subquery is not doing anything.

My whole query:

SELECT DISTINCT    a.[Recording Date],     REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(        TRIM([Document Number]),'0','n'),'1','n'),'2','n'),'3','n'),'4','n'),'5','n'),'6','n'),'7','n'),'8','n'),'9','n') as patternFROM     [TPEConversionTeam].[dbo].[KY_Shelby_Recorder_History] aWHERE       REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(        TRIM([Document Number]),'0','n'),'1','n'),'2','n'),'3','n'),'4','n'),'5','n'),'6','n'),'7','n'),'8','n'),'9','n') = 'nnnnnn-n'      (SELECT MIN([Recording Date]) AS MIN_DATE       FROM [TPEConversionTeam].[dbo].[KY_Shelby_Recorder_History]       UNION       SELECT MAX([Recording Date]) AS MAX_DATE       FROM [TPEConversionTeam].[dbo].[KY_Shelby_Recorder_History])

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>