Find Jobs
Hire Freelancers

tSQL date find

$10-30 USD

Completed
Posted almost 3 years ago

$10-30 USD

Paid on delivery
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 /
Project ID: 30771544

About the project

2 proposals
Remote project
Active 3 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
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
User Avatar
Hi, I have good experience in SQL, I can give you the sp as you expected, looking forward your ping. Thanks
$20 USD in 1 day
5.0 (1 review)
1.4
1.4

About the client

Flag of UNITED STATES
Beavercreek, United States
5.0
173
Payment method verified
Member since Oct 28, 2007

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.