473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Date calculation in SQL 2005

92
Hai,

Suggest me, how can i check whether From Date and To Date is stored already.
I want to update Values for particular period of date. if i allocate the Date for particular person. It should not accept value for that date, till that date is set free. it must show Data Already exist. It should check both From Date and To Date.

Suggest me with Query. if i extend the period of that period. they first entry must set to 0 and new entry must become 1. How can i do this

Thanks in Advance
May 27 '08 #1
12 2258
Delerna
1,134 Expert 1GB
You can use in a stored procedure
something like
Expand|Select|Wrap|Line Numbers
  1. IF EXISTS(
  2.                   Select 1 FROM TableToCheck 
  3.                   WHERE FieldToCheck=@ValueCheckingFor
  4.                         OR OtherFieldToCheck=@ValueCheckingFor
  5.                )
  6. BEGIN
  7.               Code to perform if exists
  8. END
  9.  
May 28 '08 #2
Limno
92
Thanks for Replying me.

I m hving doubt on Date Checking. how can i use between Query in Sql 2005.
I want to check whether Item rate is allocate already between particular period of date. if itz allocated already. it should show msg Already Allocate.

I m using Query as.

select ItemRate from Item where FromDate between '2008-05-07 00:00:00.000' and '2008-05-14 00:00:00.000'

but it shows msg, if i mention that starting date. i need. between dates.

Plz Help me.

Thanks in Advance.






You can use in a stored procedure
something like
Expand|Select|Wrap|Line Numbers
  1. IF EXISTS(
  2.                   Select 1 FROM TableToCheck 
  3.                   WHERE FieldToCheck=@ValueCheckingFor
  4.                         OR OtherFieldToCheck=@ValueCheckingFor
  5.                )
  6. BEGIN
  7.               Code to perform if exists
  8. END
  9.  
May 30 '08 #3
code green
1,726 Expert 1GB
At first I thought this could be a date format issue but the format you are using looks good.
Expand|Select|Wrap|Line Numbers
  1. select ItemRate from Item where FromDate between '2008-05-07 00:00:00.000' and '2008-05-14 00:00:00.000'
Are you aware that the BETWEEN function is inclusive of the dates submitted?
May 30 '08 #4
Limno
92
At first I thought this could be a date format issue but the format you are using looks good.
Expand|Select|Wrap|Line Numbers
  1. select ItemRate from Item where FromDate between '2008-05-07 00:00:00.000' and '2008-05-14 00:00:00.000'
Are you aware that the BETWEEN function is inclusive of the dates submitted?

But this code is not working, wht i need the answer. i dont want to allocate item between this date if it allocated to someother item rate.

Suggest me with Query how i can do this.
May 30 '08 #5
code green
1,726 Expert 1GB
OK slow down.
I think we are misunderstanding your problem.
Your question was
how can i check whether From Date and To Date is stored already
Then repeated
I want to check whether Item rate is allocate already between particular period of date
.But now it sounds like you have an UPDATE problem
i dont want to allocate item between this date if it allocated to someother item rate
. I am afraid the following is not very helpful
But this code is not working
A table structure and your desired result would be helpful
May 30 '08 #6
Limno
92
Sorry i got that first query answer, which i posted before. But now i need to check Between Date.
Can u Suggent me query.
May 30 '08 #7
code green
1,726 Expert 1GB
There is nothing wrong with this
Expand|Select|Wrap|Line Numbers
  1. select ItemRate from Item where FromDate between '2008-05-07 00:00:00.000' and '2008-05-14 00:00:00.000'
So what do you mean by
But now i need to check Between Date.
May 30 '08 #8
Limno
92
There is nothing wrong with this
Expand|Select|Wrap|Line Numbers
  1. select ItemRate from Item where FromDate between '2008-05-07 00:00:00.000' and '2008-05-14 00:00:00.000'
So what do you mean by

Itz not working. Only if i give this date '2008-05-07 00:00:00.000', it shows msg as Already exist. i need between date. if i give '2008-05-08 00:00:00.000' to is it work correctly or not.

Plz reply me.

Thanks in Advance.
Limno
May 30 '08 #9
code green
1,726 Expert 1GB
Itz not working.
Please don't use this term. It is no help at all and very frustrating when people are trying to help.
Only if i give this date '2008-05-07 00:00:00.000',
Give this date where? Show the query.
i need between date. if i give '2008-05-08 00:00:00.000' to is it work correctly or not.
To use BETWEEN you need two dates.
First the start date and then the end date.
The dates are inclusive.
But I have already told you all of this.
If this query IS NOT WORKING you need to explain the result you expect.
At least show some code.
There may be a syntax error
May 30 '08 #10
Limno
92
Thank you for replying me.

I am hving column fields as

1. item_id
2. FromDate
3. ToDate
4. ItemName
5. Rate

Here my problem is, i want to allocate Date for Particular ItemName(Eg. Sugar) as from some date to some date. if i allocate rate for that same ItemName(Sugar), it should not accept its entry. it should display some error msg. for this how can i write sql query to solve this problem. I want to check both FromDate column and ToDate column date.




Please don't use this term. It is no help at all and very frustrating when people are trying to help.
Give this date where? Show the query.
To use BETWEEN you need two dates.
First the start date and then the end date.
The dates are inclusive.
But I have already told you all of this.
If this query IS NOT WORKING you need to explain the result you expect.
At least show some code.
There may be a syntax error
May 31 '08 #11
code green
1,726 Expert 1GB
You have been given a number of suggestions already and your reply has only been
It's not working
or
show me the query
Please show the query you have constructed so far then we can be sure of what you are trying to do.
Because I have no idea if you are attempting an UPDATE or an INSERT or a SELECT then dispaying the results via a program.
Jun 2 '08 #12
Limno
92
You have been given a number of suggestions already and your reply has only been or
Please show the query you have constructed so far then we can be sure of what you are trying to do.
Because I have no idea if you are attempting an UPDATE or an INSERT or a SELECT then dispaying the results via a program.

Thanks you for ur suggestions,

i found that my answer. I used the query by using where condition not by BETWEEN query.
Jun 4 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
6
by: Pete | last post by:
Hi Guys I have a form which must calc the difference between 2 date fields and return the result in a third field. I have the following code but it does not seem to work. Can anyone tell this...
1
by: Apple | last post by:
May anyone can teach me how to calculate with date, my calculation is : Date field (2005/01) + numberic field (3) = 2005/04(YYYY/MM)
2
by: Gershon | last post by:
I have a simple table including First Name, Last Name, Start Date. I need to create a report listing First, Last and the number of days since Start Date. The First and Last names are easy. How do I...
1
by: John Feeley | last post by:
am tring to add a number of years to a dob. im doing this by adding my date+years*365.26 I get a string of numbers. I then convert the number in the next column to actual date again. I'm getting...
1
by: untiroalaire | last post by:
Hi, here's what I'd like to do: get the time difference (Elapsed) between the "received date" field for all emails (running total) I've dumped into access from outlook and summarize at the...
3
by: Glencannon4424 via AccessMonster.com | last post by:
Hello, I have what I believe amounts to a Date Serial issue. I have the following columns in my table: Hire-Date Hire-Year WTD-RATE Wks-in-Yr
1
by: c8tz | last post by:
This is a query I have created that picks up the top 3 dates for this data (for example) : Tree Pos2 Date 1 15 23/08/2005 1 20 12/02/2006 1 32 15/10/2006 ...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.