Вы можете использовать DATEFROMPARTS , чтобы построить дату в месяце (первый или последний день месяца).
declare @MsgText nvarchar(1000) = N'Captured Credit Card: MasterCard, xxxx-xxxx-xxxx-xxxx, 09/19. Set as Default.'
select SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) -2, 2) AS [Month]
,'20' + SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) + 1, 2) AS [Year]
-- First day of the month
select DATEFROMPARTS(CAST('20' + SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) + 1, 2) as int), CAST(SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) -2, 2) as int), 1) as FirstDayOfMonth
-- Last day of the month - add 1 month to the date above and go back 1 day
select DATEADD(day, -1, DATEADD(month, 1, DATEFROMPARTS(CAST('20' + SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) + 1, 2) as int), CAST(SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) -2, 2) as int), 1))) as EndOfMonth
Или, что еще лучше, используйте функцию EOMONTH :
select EOMONTH(DATEFROMPARTS(CAST('20' + SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) + 1, 2) as int), CAST(SUBSTRING(@MsgText, CHARINDEX('/', @MsgText, 0) -2, 2) as int), 1)) as EndOfMonth