What I need to do is find the Day of the Week and the Month within the Date Range of the data and return to me that value.
I have the first part of the procedure;
USE [Test-DB]
GO
/****** Object: StoredProcedure [dbo].[proc_parseXLRule] Script Date: 7/7/2021 9:08:01 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[proc_parseXLRule](
@OldRule varchar(1000),
@NewRule varchar(1000) output
) AS
BEGIN
SET NOCOUNT ON;
--SET @OldRule= '10JAN-31JUL/XR:P$100|90 DR:P$50~01AUG-20NOV/XR:P%50 DR:P%25~21NOV-09JAN/XR:NR'
DECLARE @NowDay VARCHAR(2)
DECLARE @Today DateTime
DECLARE @NowMonth VARCHAR(3)
SET @NowDay = RIGHT('00' + CONVERT(NVARCHAR(2), DATEPART(DAY, GETDATE())), 2)
SET @Today=getdate()
SET @NowMonth=UPPER(FORMAT(@Today,'MMM','en-US'))
SELECT value, @NowDay as 'NowDay', @NowMonth as 'NowMonth'
FROM STRING_SPLIT(@OldRule, '~')
WHERE RTRIM(value) <> '';
DECLARE @pos INT
DECLARE @len INT
DECLARE @day VARCHAR(2)
DECLARE @month VARCHAR(3)
SET @pos = 0
SET @len = 0
WHILE CHARINDEX('~', @OldRule, @pos+1)>0
BEGIN
SET @len = CHARINDEX('~', @OldRule, @pos+1) - @pos
SET @NewRule = SUBSTRING(@OldRule, @pos, @len)
PRINT @NewRule -- for debug porpose
PRINT 'NowDay: '+@NowDay
PRINT 'NowMonth: '+@NowMonth
--NEED TO LOOP THRU THE RESULTS AND FIND THE MATCH
SET @pos = CHARINDEX('~', @OldRule, @pos+@len) +1
END
END
--------------------------------------and the call:
exec dbo.proc_parseXLRule @OldRule='10JAN-01JUL/XR:P$100|90 DR:P$50~01AUG-20NOV/XR:P%50 DR:P%25~XR:P$300~21NOV-09JAN/XR:NR', @NewRule=''
-----------------What I expect back is Line 3: XR:P$300
as 07JUL does not fall in between any of the other date ranges and since there is no date range on line 3 that is the value I need returned
If NowDay and NowMonth was 10JUN
I would expect back: XR:P$100|90 DR:P$50
trimming off everything upto and including the /
Hello,
As an expert in t-sql, I am very much interested to finish the procedure as required. Looking forward to have a positive response from you.
Question: Is it possible to have multiple values as output?
Thanks
$40 USD in 1 day
5.0 (169 reviews)
7.6
7.6
2 freelancers are bidding on average $30 USD for this job