Showing posts with label dates. Show all posts
Showing posts with label dates. Show all posts

Thursday, March 8, 2012

ABS () and dates

What would the Sql syntax look like if I wanted to select +/- 10 days of a d
elivery date.
For instance; Table has Actual Delivery Date & Expected Delivery date, and u
sing the ABS Sql function, I want to select only the rows from the table tha
t were delivered with +/- 10 days.
And even if it's not the best way to do it, I would really like the info on
ABS.
Any ideas?
Thanx!Use DATEADD function like:
BETWEEN DATEADD ( d, -10, dt ) AND DATEADD ( d, 10, dt )
Anith|||I don't know your table structure or sample data, but here's a guess:
WHERE ABS(DATEDIFF(DAY, ActualDate, ExpectedDate)) <= 10
"Jude" <judes@.email.uophx.edu> wrote in message
news:%23NQBlSwQGHA.1868@.TK2MSFTNGP09.phx.gbl...
What would the Sql syntax look like if I wanted to select +/- 10 days of a
delivery date.
For instance; Table has Actual Delivery Date & Expected Delivery date, and
using the ABS Sql function, I want to select only the rows from the table
that were delivered with +/- 10 days.
And even if it's not the best way to do it, I would really like the info on
ABS.
Any ideas?
Thanx!|||Trust me I would, but someone taking a class asked me this question & I said
I had never used this function, but knew where to go to ask the experts!
Thanx!
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:u1RNgfwQGHA.4960@.TK2MSFTNGP12.phx.gbl...
> Use DATEADD function like:
> BETWEEN DATEADD ( d, -10, dt ) AND DATEADD ( d, 10, dt )
> --
> Anith
>|||Fantastic, Thanx so much Aaron! This is a favor for a friend who is taking
a class, and since I haven't used this function & would just use DateDiff
functions, I didn't have an answer. I knew the experts in here would
though!
Thanx again!!!!!
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:e%23zWkBxQGHA.1160@.TK2MSFTNGP09.phx.gbl...
>I don't know your table structure or sample data, but here's a guess:
> WHERE ABS(DATEDIFF(DAY, ActualDate, ExpectedDate)) <= 10
>
> "Jude" <judes@.email.uophx.edu> wrote in message
> news:%23NQBlSwQGHA.1868@.TK2MSFTNGP09.phx.gbl...
> What would the Sql syntax look like if I wanted to select +/- 10 days of a
> delivery date.
> For instance; Table has Actual Delivery Date & Expected Delivery date, and
> using the ABS Sql function, I want to select only the rows from the table
> that were delivered with +/- 10 days.
> And even if it's not the best way to do it, I would really like the info
> on ABS.
> Any ideas?
> Thanx!
>
>

Sunday, February 19, 2012

about select between help pls

well i have 2 input date form and to.

"date_from" varchar variable

and "date_to" varchar variable

where in i want to select only the dates between the two variables only.

example

date_from -date_to contains= "200702"-"200705"

and everything that starts from 200702 to 200705 will be output.

can someone help me or give some similar examples regarding this?

thanks...

Select * from Transaction Where Date_From >= (Cast(Year(TransactionDate) as varchar) + Cast(Month(TransactionDate) as varchar)) AND Date_To <= (Cast(Year(TransactionDate) as varchar) + Cast(Month(TransactionDate) as varchar))|||

My suggestion is not to use the BETWEEN operator, but instead use the >= and < operators. This, along with adding 1 day to the upper bounds of the "to" date, will help to avoid the pitfalls you can encounter when trying to work around the time portion of dates.

Try something like this:

DECLARE @.date_from datetime

DECLARE @.date_to datetime

SELECT @.date_from = '20070201', @.date_to = '20070530' -- note the the time portion of the date will default to midnight 00:00:00.0000

SELECT @.date_to = DATEADD(d, 1, @.date_to) -- add 1 day to the ending date

SELECT

someColumns

FROM

someTable

WHERE

myDate >= @.date_from AND myDate < @.date_to

|||

how about this one?

Public Sub read_records(ByVal nyutancd As String, ByVal date_from_new As String, ByVal date_to_new As String)

'配送依頼のデータ取得
'SQL作成
db = New TDataCenter.db.TDataCenter("venus", "venus", "threesupport", "postgres", "postgres")

date_from = ""
date_to = ""
syain_name = ""
product = ""

Dim objReader As PgSqlDataReader

'objReader = db.GetSQLReader(String.Format("Select distinct urr_urinenget,urr_etancd,urr_scd,urr_urikbn,urr_zurgsuu,urr_zurgkin,urr_zsirgkin,urr_curgsuu,urr_curgkin,urr_csirgkin,urr_gurgsuu,urr_gurgkinn,urr_gsirgkin,urr_turgkin,urr_tsirgkin,urr_kousindate from urr")))
objReader = db.GetSQLReader(String.Format("Select distincturr_urinenget,sn_syainnm,sy_snm,urr_urikbn,kt.kt_nm fromurr inner join sy on sy.scd = urr.urr_scd inner join sn on sn.syaincd = urr_etancd inner join kt on kt.kt_cd = urr.urr_urikbn and kt.kt_kbn='cm07'where urr_urinenget between {0} and {1} group by urr_urinenget,sn_syainnm,sy_snm,urr_urikbn, kt.kt_nm ", TDataCenter.db.TDataCenter.SingleQuatedStr(date_from_new), TDataCenter.db.TDataCenter.SingleQuatedStr(date_to_new)))

do you think it will work?

|||

natasha_arriell:

do you think it will work?

That approach is insecure. Do not use placeholders and string substitution; always use parameters.

I have no idea what processing SingleQuatedStr does to those string values. I have no idea what those string values contain. And I have no idea what sort of data is stored in the urr_urineget column. Your best bet is to use some edge case data and try it yourself to see if you are getting the desired result.