sql server - Calculating 2 weeks for every week SQL -
i'm still new sql question asking may easy you. creating study every week generates prior 14 days (or 2 weeks) of funded contracts. know has hardcoded specific company. id specific company '55' can help me function? query know not yet finished stuck on how come in date function this.
create proc [dbo].[spadminfundeddateee] begin select c.program_id, d.dealer_code,b.last_name dealername, a.account_no, a.vin, ((e.last_name)+','+(e.first_name)) name, a.funded_date, a.cancel_refund_date, a.purchase_date,a.miles, a.duration,a.sale_price,a.number_of_payments, a.sales_tax, a.downpayment tdealer d bring together tcontact b on d.contact_id = b.contact_id bring together tcontract on d.dealer_id = a.dealer_id bring together tcompany c on d.company_id= c.company_id bring together tcontact e on e.contact_id = a.contact_id c.program_id = 55 , a.funded_date between end exec spadminfundeddateee '05/1/2014','05/30/2014','55'
in order check if a.funded_date between today's date , 2 weeks ago, going need several sql server functions. first 1 getdate(). returns current date , time datetime value.
now, want check date parameter (not time). if runs stored procedure @ 1pm, don't want eliminate of info before 1pm day 14 days ago. want data, no matter time, origin 14 days ago. solve issue, want alter getdate() date only. so, cast(getdate() date). today, homecoming 6-18-14.
lastly, want check date 2 weeks ago. dateadd allows add together amount of time specify date or time. in case, want info 14 days ago. going dateadd(dd, -14, cast(getdate() date)).
since between inclusive, need set together!
between dateadd(dd, -14, cast(getdate() date)) , cast(getdate() date)
sql sql-server hardcode
No comments:
Post a Comment