Updating Dates

Sep 8, 2006

I am building a site which provides an online handbook. I have two fields - date and update_date. The first is when the contents was originally entered and the second is meant to be updated every time the record is changed.
I have no idea how to do this - any help welcome.

View 7 Replies


ADVERTISEMENT

Updating And Replacing Dates

Dec 17, 2007

I'm the assistant to the assistants assistant and have no SQL base at all but have to change dates in our SQL database. I've got the script for how to do an update/replace for non date fields and have been successful at that. Unfortunately when I try to use the script to change date fields it does not work. It goes through the process and acts like it is working (even asks me if I want to update the records) but when I look in the database the dates have not changed. Below is the script that I am using, any help you can give me will help me keep my job (and pay for the beer I'm sure to need after work today) Thanks in advance for your help. I am trying to change the date '30/08/2007' to '28/08/2008'.

My Script:

update Main_table set valuedate=replace(valuedate,'30/08/2007','28/08/2008')
where country='FR'
and valuedate='30/08/2007'

View 4 Replies View Related

Problem With Inserting Or Updating Dates In Mssql 2000

Apr 12, 2006

Hello.I've read many topics about this problem but i couldn't figure it out.I use form where user must insert 2 dates  using texboxes.-One is required and other is optional.Sql 2000 is inserting either '20061105' or '2006.11.05' on insert update but select query returns 05.11.2006 on my report. Question 1.How do I insert or update dates from my form where date is entered dd.mm.yyyy to sql 2000 table?question 2. What to do if user left optional texbox date empty.I'm using SP and function with arguments (byval texbox1.text as date, byval texbox2.text as date)and parameters @date1, sqldbtype date =texbox1.text

View 2 Replies View Related

Transact SQL :: Updating Table Rows With Overlapping Dates (extend)

Dec 2, 2015

This question is extension from the topic Updating table Rows with overlapping dates: [URL] .....

I am actually having a table as following:

Table Name: PromotionList

Note that the NULL in endDate means no end date or infinite end date.

ID PromotionID StartDate EndDate Flag
1 1 2015-04-05 2015-05-28 0
2 1 2015-04-23 NULL 0
3 2 2015-03-03 2015-05-04 0
4 1 2015-04-23 2015-05-29 0
5 1 2015-01-01 2015-02-02 0

And I would like to produce the following outcome to the same table (using update statement): As what you all observe, it merge all overlapping dates based on same promotion ID by taking the minimum start date and maximum end date. Only the first row of overlapping date is updated to the desired value and the flag value change to 1. For other overlapping value, it will be set to NULL and the flag becomes 2.

Flag = 1, success merge row. Flag = 2, fail row

ID PromotionID StartDate EndDate Flag
1 1 2015-04-05 NULL 1
2 1 NULL NULL 2
3 2 2015-03-03 2015-05-04 1
4 1 NULL NULL 2
5 1 2015-01-01 2015-02-02 1

The second part that I would like to acheive is based on the first table as well. However, this time I would like to merge the date which results in the minimum start date and End Date of the last overlapping rows. Since the End date of the last overlapping rows of promotion ID 1 is row with ID 4 with End Date 2015-05-29, the table will result as follow after update.

ID PromotionID StartDate EndDate Flag
1 1 2015-04-05 2015-05-29 1
2 1 NULL NULL 2
3 2 2015-03-03 2015-05-04 1
4 1 NULL NULL 2
5 1 2015-01-01 2015-02-02 1

Note that above is just sample Data. Actual data might contain thousands of records and hopefully it can be done in single update statement.

Extending from the above question, now two extra columns has been added to the table, which is ShouldDelete and PromotionCategoryID respectively.

Original table:

ID PromotionID StartDate EndDate Flag ShouldDelete PromotionCategoryID
1 1 2015-04-05 2015-05-28 0 Y 1
2 1 2015-04-23 2015-05-29 0 NULL NULL
3 2 2015-03-03 2015-05-04 0 N NULL
4 1 2015-04-23 NULL 0 Y 1
5 1 2015-01-01 2015-02-02 0 NULL NULL

Should Delete can take Y, N and NULL
PromotionCategoryID can take any integer and NULL

Now it should be partition according with promotionid, shoulddelete and promotioncategoryID (these 3 should be same).

By taking the min date and max date of the same group, the following table should be achieve after the table is updated.

Final outcome:

ID PromotionID StartDate EndDate Flag ShouldDelete PromotionCategoryID
1 1 2015-04-05 NULL 1 Y 1
2 1 2015-04-23 2015-05-29 1 NULL NULL
3 2 2015-03-03 2015-05-04 1 N NULL
4 1 NULL NULL 2 Y 1
5 1 2015-01-01 2015-02-02 1 NULL NULL

View 2 Replies View Related

Want To Use Parameters To Filter For Dates Between Two (parameter, User-input) Dates

Mar 2, 2006

SQL 2005 Dev

How can I do this with Parameters? I can get a single parameter to filter for a single date (or even a combo list of the dates in DB). But I want my parameters to interact so that they specify a range. Is this possible?

View 3 Replies View Related

T-SQL (SS2K8) :: Calculate Sum Of Dates Minus Repetitive Dates

Jul 18, 2014

Today I have got one scenario to calculate the (sum of days difference minus(-) the dates if the same date is appearing both in assgn_dtm and complet_dtm)/* Here goes the table schema and sample data */

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[temp_tbl]') AND type in (N'U'))
DROP TABLE [dbo].[temp_tbl]
GO
CREATE TABLE [dbo].[temp_tbl](
[tbl_id] [bigint] NULL,
[cs_id] [int] NOT NULL,
[USERID] [int] NOT NULL,

[code]....

View 9 Replies View Related

T-SQL (SS2K8) :: Insert Into Table Dates In Between Two Dates

Feb 28, 2015

I have a table that has hotel guests and their start stay date and end stay date, i would like to insert into a new table the original information + add all days in between.

CREATE TABLE hotel_guests
(
[guest_name] [varchar](25) NULL,
[start_date] [date] NULL,
[end_date] [date] NULL,
[comment] [varchar](255) NULL

[code]...

View 7 Replies View Related

Updating A Table By Both Inserting And Updating In The Data Flow

Sep 21, 2006

I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.

Any suggestions?

View 7 Replies View Related

Comparing Dates With Today Dates

Jun 21, 2005

I want to know if there is a way to compare dates in the sql statement with dates that I input into a database and todays date.  the datatype that I'm using is smalldatetime.The statement I used is:Select Date from Table where Date > 'Today.now'I get an errorCould this be done or is there another approach?

View 1 Replies View Related

Generate Dates Between Two Dates

Nov 8, 2006

Hi,

I have a table which records employees'time-off records. There are 6 columns in this TimeOff table. They are RequestID, EmpName, StartDate, EndDate, Type, NumofDays. I have another table which has all the dates from 01/01/1950 to 01/01/2056.

I am trying write a query which lists all the dates between the timeoff startdate and enddate, including the the start and end dates, but my query so far only lists the start and end date in a timeoff record:

SELECT D.[Date], Datename(dw,D.[Date]) AS Weekday
FROM Dates D LEFT JOIN TimeOff T ON D.[Date] = T.OffStartDate OR D.[Date] = T.OffEndDate
WHERE (OffType = 'Sick Day' AND EmpName = 'Cat White') AND (D.[Date] BETWEEN T.StartDate AND T.EndDate)

Any advice will be greatly appreciated!

View 1 Replies View Related

Getting Individual Dates Between 2 Dates

Mar 4, 2008

Has anyone ever written a function to retrieve all individual dates between two given dates? Using DATEDIFF I can get the number of days between two dates. However I need to iterate through the days to identify weekend and holiday dates. Has anyone ever written a function to do this?

So, if select datediff(d,'07/01/2007','07/15/2007') as NumOfDays returns 14, I'd need to iterate through the 14 days and get the weekends and holidays. Would I have to use a cursor to iterate through the days?

View 13 Replies View Related

Leap Year Dates Causing Error When You Pull Dates For Non Leap Year

Feb 28, 2008



I'm trying to generate this query, that displays Budget Current Year , Actual Current Year and Prior Year Revenue. When It comes to the Budget and Actual everything works fine, however when I try to add the query for the Prior Year I get an error, and I realized that the leap date is causing the error


Here is what I'm trying to generate






InnCodeID
Quarterly
Monthly
Days
Period
Year
BARmRev
AARmRev
PYRmRev

ADDIS
Q1
Jan
1
1
2008
NULL
NULL


ADDIS
Q1
Jan
1
1
2008
3462.14
5107.65


ADDIS
Q1
Jan
1
1
2008
NULL
NULL


ADDIS
Q1
Jan
1
1
2008
NULL
NULL



Here is the error that I'm getting:



Code Snippet

Msg 242, Level 16, State 3, Line 1

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

(4834 row(s) affected)



Here is my Transact-SQL Syntax (summarized because I Couldn't post it):

SELECT

(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01'

AND Year(dbo.Trans.TR_Date) = Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1'

THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN

(SELECT Trans1.TR_Amount

FROM dbo.Trans Trans1

WHERE Trans1.TR_Dept = '10' AND TR_Main = '5120' AND TR_Sub = '01' AND trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date)

AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Year(dbo.CurrentDate.CurrDate) AS varchar(4))) AS datetime)

AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND trans1.datatype = dbo.Trans.DataType) ELSE NULL END) * - 1 AS BARmRev,


--AA Script Here AS AARmRev,

(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01' AND Year(dbo.Trans.TR_Date)

= Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1' THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN

(SELECT SUM(Trans1.TR_Amount)

FROM dbo.Trans Trans1

WHERE RIGHT(RTRIM(Trans1.TR_Dept), 2) = '10' AND Trans1.TR_Main = '5120' AND Trans1.TR_Sub NOT BETWEEN '04' AND '05' AND

trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2))

+ '/' + CAST(Year(dbo.CurrentDate.CurrDate)-1 AS varchar(4))) AS datetime) AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND

trans1.datatype = '0') ELSE NULL END) * - 1 AS PYRmRev



FROM dbo.EntityDef INNER JOIN

dbo.Trans ON dbo.EntityDef.ED_Property_ID = dbo.Trans.TR_Entity INNER JOIN

dbo.CurrentDate INNER JOIN

dbo.DimTime ON YEAR(dbo.DimTime.TimeDate) = YEAR(dbo.CurrentDate.CurrDate) ON dbo.Trans.TR_Date = dbo.DimTime.TimeDate

WHERE (dbo.EntityDef.ED_Property_ID = 'ADDIS')

ORDER BY dbo.EntityDef.ED_Property_ID, dbo.DimTime.TimeDate


I appreciate all your help

Thanks

View 13 Replies View Related

Sql Dates

Mar 30, 2007

Hello All,
 I am trying to Add certain number of days to a particular date.
and my requirement is that it need to exclude all saturdays and sundays and then give me the resultant date in Sqlserver.
 Please can anyone help me in achieving it.
 thanks
Shiva Kumar

View 2 Replies View Related

Dates

Jan 10, 2002

Hi can anyone help me , or am I on the wrong track.

Is there any easy way to create a stored procedure that inserts into a table the relevant months dates into a table based on the month and year as parameters.
I.e say the parameters passed are 01/2001 hence based on this all of the month of January 2001 dates are inserted into a table in this format : 'Jan 01 2001 12:00:00'

Thanks

View 1 Replies View Related

SQL Dates

Apr 19, 2004

OK, so I can return (& therefore use) the last day of last month using

select (GETDATE()- DATEPART ( dd , GETDATE()))

Which returns 31-03-2004 (dd-mm-yyyy)

Has anyone a good way of determining a way of deriving say a date such as 01-01-2004 (1st Jan)....

I'd like to get some data where my dmd.sdate falls always in the previous quarter.. but would like it to be not hard coded...

Currently I have

SELECT cust.no,
cust.surname,
dmd.csan,
dmd.sdate
FROM pdunity.dbo.cust cust,
pdunity.dbo.dmd dmd
WHERE cust.rowno = dmd.rowno_custdmd_cust
AND(dmd.sdate
BETWEEN '01/01/2004'
AND(GETDATE()- DATEPART ( dd , GETDATE())))
ORDER by dmd.sdate asc

Is there some form of function I can use to return 01/01/2004 automatically ?

Will

View 6 Replies View Related

Dates ...

Nov 21, 2005

why does this sql return the dates in different formats? Is it a default setting on the server or do i just handle it on SQL?

use northwind

select top 20 orderdate from orders

select top 20 left(orderdate,10) from orders


thanks

fatherjack

View 1 Replies View Related

Dates For The UK

Feb 11, 1999

We are deploying a system in the UK in SQL Server 6.5. They want the date to default to dd/mm/yy. Is there a way to set this on a permanent basis? Is there a way to set the server so any time a date is display, including getdate(), the result is dd/mm/yy?

View 2 Replies View Related

Dates Between 2 Other Dates

Aug 16, 2002

Hi All

I have a table which contains apart from other fields, 2 dates. i.e. startdate and enddate.

The startdate is always less than / equal to enddate.

I want to write a stored proc where I will give a date as a parameter and it should give me all the records there my date is between the startdate and the enddate.

Also I want to create a temp table in the procedure and the table gets populated with all the dates that comes between startdate and enddate, both dates inclusive.

I know this might be a tall order, but I am new to writing stored procedure, so I will be obliged if somebody can help me out

Yusuf

View 1 Replies View Related

Dates

Apr 11, 2008

How would I pull just a list of dates for say the next year or two

View 1 Replies View Related

Dates

Apr 18, 2008

I have an assignment using SQL this is the first time i have used it but i can understand the basics.

It is for an instrument service company and i need to find what instruments have not been serviced for a year.
i already know i have to:

SELECT instrument number, date of last service
FROM Instrument table

but after this i am unsure what code i can use in order to find all instruments that have not been servided in over 365 days what code can is best to use?

View 4 Replies View Related

Dates Between Two Dates

Apr 26, 2008

Hi friends,
I need to display the dates in between two dates without using tables. two dates are today date and 10th date from today date.

View 17 Replies View Related

Dates

Apr 30, 2008

I have a columns with storeID's and dates i need to be able to find the difference of date for a certain store for its Min(Date) to the End of that Month

example

Date StoreID Difference of Date to end of the
Month
2008-01-02 00:00:00.000 163
2008-01-03 00:00:00.000 165
2008-01-01 00:00:00.000 167
2008-01-02 00:00:00.000 180

View 2 Replies View Related

Sum Between Dates

May 7, 2008

Hi,

I am trying to calculate our job value and product costs over a given time period. But if I run my query, the numbers just dont look right at all. Please can you have a look at this query and see if anything stands out?

-- FINISHED PRODUCTS PRODUCTION REPORTS DATA
-- gets current WIP Job information.
-- requires item details from this.
USE Staging
-- declare start and end variables
DECLARE @Start DATETIME
DECLARE @End DATETIME
SET DATEFORMAT DMY
SET @Start = '01/01/2008'
SET @End = '01/02/2008'
SELECT
SUM(jbs.Value) AS ProducionValue,
SUM(prd.Cost) AS Cost,
CONVERT(CHAR(10), @Start, 103) AS [From],
CONVERT(CHAR(10), @End, 103) AS [End]
FROM
(
SELECT
Job.[Job No],
Job.[Cust Name],
Job.[Req'd Date],
Job.ProdStartActual,
Job.Dept,
[Job].[Value],
Job.Loan
FROM
Job
WHERE
Job.[ProdStartActual] BETWEEN @start AND @End AND
Job.Cancel = 0 AND
Job.Sales = 1 AND
Job.Invoiced = 1 OR
Job.[ProdStartActual] BETWEEN @start AND @End AND
Job.Cancel = 0 AND
Job.Sales = 1 AND
Job.Invoiced = 2
) AS jbs INNER JOIN
(
SELECT
Item.[Job No],
Item.[Code]
FROM
Item
) AS itm ON jbs.[Job No] = itm.[Job No] INNER JOIN
(
SELECT
Product.[Product Code],
Product.[Cost]
FROM
Product
) AS prd ON itm.Code = prd.[Product Code]

"Impossible is Nothing"

View 5 Replies View Related

Dates Between

Jun 9, 2008

If I give the from date and to date i should get all dates the between from and to.

eg:
from:'01-June-2008'
To:'03-june-2008'

Result:

Date
'01-June-2008'
'02-June-2008'
'03-June-2008'

Thanks in advance..,


cool...,

View 9 Replies View Related

Set Of Dates

Jul 23, 2005

I've got a table (TYPE, DAYMTH) where it is a compound key and theDAYMTH is a datetime but all years are 1900 ONLY THE day and month aresignificant.What I want to do is for each type, find the next n dates - so forexample:TYPE DAYMTH1 1900-02-201 1900-05-051 1900-09-141 1900-11-112 1900-03-032 1900-07-07if I want to get the next 3 dates after 22 June 2005 it should give me:1 2005-09-141 2005-11-111 2006-02-202 2005-07-072 2006-03-032 2006-07-07so, anyone got any bright ideas?I've started down this route:create table #year (yr int)insert into #year values(2005)insert into #year values(2006)insert into #year values(2007)insert into #year values(2008)select *,convert(datetime,convert(varchar,yr) +substring(convert(varchar,daymth,20),5,20),20)from DAYMTHtable,#yearwhere convert(datetime,convert(varchar,yr) +substring(convert(varchar,daymth,20),5,20),20) > getdate()order by type,convert(datetime,convert(varchar,yr) +substring(convert(varchar,daymth,20),5,20),20)and although this seems to be a good start I wonder if there are bettersolutions. Also any quick ideas on how to finish if I decide to followmy existing thought process?thanksPhil

View 3 Replies View Related

SQL Between Dates

Sep 13, 2006

For some reason guys my SQL string isn't working and I'm probably doingsomething stupid?SELECT *FROM sol_sessionSELECT *FROM SOL_SessionWHERE DateGiven '10/09/2006' AND <'13/09/2006'The 'DateGiven' field is a DateTime field, and I can't see quite whatswrong??I simply get a Syntax error!Cheers, Ash

View 15 Replies View Related

ISO Dates?

Jul 20, 2005

To support an application, I am integrating it with with Sqlserver2000. The task is simple: get the data at regular intervals, andwrite it into a table dedicated for that application. One of thefields I receive is a date, and it is formatted as an ISO date. Asample value looks like this: "2004-07-09-15.37.52.077258".SQLServer doesn't support this date format, though. The closest Ihave found is the style code "21" or "121" which accepts input as"yyyy-mm-dd hh:mi:ss.mmm". I have looked at using several replace()and convert() calls but no solution yet.Is there a way to transform the data to conform to this style acceptedby Sqlserver? I would like to do this in the INSERT statement itselfand not have to code application logic (i.e., user-defined function,etc.) for it.

View 2 Replies View Related

Help! Dates And SQL

Jul 20, 2005

HiI would like to create a SP where it will populate TableA based from TableB.TableB will be populated on a monthly basis using a DTS and within that Iwould like to run the SP to populate TableA.Can someone here please help me create the sql statements as a startingpoint.TIA!BobTableB (source)from_date to_date curr_code ex_rate1/1/2004 1/10/2004 CAD .750001/11/2004 1/16/2004 CAD .743211/17/2004 2/4/2004 CAD .722222/5/2004 2/20/2004 CAD .711112/21/2004 2/28/2004 CAD .778883/1/2004 3/3/2004 CAD .790023/4/2004 3/14/2004 CAD .768033/15/2004 3/23/2004 CAD .700223/24/2004 4/2/2004 CAD .73365etc...TableA (destination):date curr_code ex_rate1/2004 CAD 0.738477 calculation:(.75000+..74321+.72222) / 32/2004 CAD 0.737403(.72222+.71111+.77888) / 33/2004 CAD 0.74798(.79002+.76803+.70022+.73365) / 4etc..

View 3 Replies View Related

Get Dates NOT Between X And Y

Jul 27, 2006

Hi. I hope this is the write place to post this, I hope it is.



basically, I want to be able to return me a query of giving me available dates in a table.

What I mean is that, if I have a table with fields including start date and end date, I want to return me the dates which are NOT listed/stored in the table.



kind of like a booking system, where you store the room reservation dates and obviously you don't want to double book that room, so I would like all the available dates to be returned back.



is this possible? how can I go about doing this?



Thanks!

View 8 Replies View Related

Dates

Mar 12, 2008

Hello people! I have a question: I have a datetime field in my database. When I add a datetime variable (in 12.03.2008 format) to stored procedure (from C# code) that actually updates that field - everything ok. but when I am trying to update a datetime field with string 12.03.2008 (no matter nvarchar or datetime type) in T-SQL code - the date that i receive - 2008-12-03, it means that month and day are swapped! How can I fix it? Thanks.

View 5 Replies View Related

Dates

Nov 7, 2006

Hi,

I have date columns in my tables defined as smalldatetime. How do I perform a Select that will retrieve records with dates equal to the date selected in a calendar control as follows:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ReservationsConnectionString %>"

SelectCommand="SELECT [TIM_Time], [TIM_ID], [TIM_Valid_From] FROM [Times] WHERE ([TIM_Time] = @TIM_Time)">

<SelectParameters>

<asp:ControlParameter ControlID="Calendar1" Name="TIM_Time" PropertyName="SelectedDate"

Type="DateTime" />

</SelectParameters>

I get no records when I know they are there - do I have to put in additional checks to cater for the time component of the column?

Thanks in advance.

View 8 Replies View Related

Comparing Dates

Jun 26, 2006

Hello,
 
I am trying to retrieve the data that are not more than 3 months. How do I do this? The closest thing that I can do is...
 
(dbo.CLASSIFIEDADS.PostDate > CONVERT(DATETIME, '2006-03-26 00:00:00', 102))
I want to be able to put 3 months in there somehow...
Thanks in Advance!

View 2 Replies View Related

Sql Server Dates :S

Aug 6, 2006

I have an application where there is a form to enter some data to the sql server 2005 database.
when the form is submitted, I also use Date.Now to insert the date the article was submitted. It enters fine. E.g. if I submitted it today, it would display 08/06/2006 (which is 06 August 2006). When getting the records,  I use, "dd MMM yyyy" to format the date according to my culture. However, the result I get is 08 June 2006
What might be the problem. I hate working with dates with sql server

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved