Update Fields With Searched First Date Record Fields

Jul 23, 2005

Hello !
I'm trying to update one table field with another table searched first
date record.
getting some problem.
If anyone have experience similar thing or have any idea about it,
please guide.

Sample case is given below.

Thanks in adv.
T.S.Negi


--Sample case

DROP TABLE TEST1
DROP TABLE TEST2

CREATE TABLE TEST1
(
CUST_CD VARCHAR(10),
BOOKING_DATE DATETIME,
BOOKPHONE_NO VARCHAR(10)
)

CREATE TABLE TEST2
(
CUST_CD VARCHAR(10),
ENTRY_DATE DATETIME,
FIRSTPHONE_NO VARCHAR(10)
)

DELETE FROM TEST1
INSERT INTO TEST1 VALUES('C1',GETDATE()+5,'11111111')
INSERT INTO TEST1 VALUES('C1',GETDATE()+10,'22222222')
INSERT INTO TEST1 VALUES('C1',GETDATE()+15,'44444444')
INSERT INTO TEST1 VALUES('C1',GETDATE()+16,'33333333')

DELETE FROM TEST2
INSERT INTO TEST2 VALUES('C1',GETDATE(),'')
INSERT INTO TEST2 VALUES('C1',GETDATE()+2,'')
INSERT INTO TEST2 VALUES('C1',GETDATE()+11,'')
INSERT INTO TEST2 VALUES('C1',GETDATE()+12,'')

--SELECT * FROM TEST1
--SELECT * FROM TEST2


/*
Sample data
TEST1
CUST_CD BOOKING_DATE BOOKPHONE_NO
C12005-04-08 21:46:47.78011111111
C12005-04-13 21:46:47.78022222222
C12005-04-18 21:46:47.78044444444
C12005-04-19 21:46:47.78033333333

TEST2
CUST_CD ENTRY_DATE FIRSTPHONE_NO
C12005-04-03 21:46:47.800
C12005-04-05 21:46:47.800
C12005-04-14 21:46:47.800
C12005-04-15 21:46:47.800

DESIRED RESULT
CUST_CD ENTRY_DATE FIRSTPHONE_NO
C12005-04-03 21:46:47.80011111111
C12005-04-05 21:46:47.80011111111
C12005-04-14 21:46:47.80044444444
C12005-04-15 21:46:47.80044444444
*/

View 3 Replies


ADVERTISEMENT

.Update Creates New Record But All Fields Null

Jan 26, 2006

Hi guys, I have made several Access-based CMSs but now I am using SQL Server. I can read the records but my first attempts at writing are resulting in new records (with new ID) but all the fields are null.
I am posting the data from a form to the same page and an if /then statement catches the flag in the URL and runs the update script below. All the field names are correct.
if request.QueryString("add")<> "" then
Dim rsUpdateEntry
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
rsUpdateEntry.Open "SELECT * from generic_country_info" , oConn, 2, 3

rsUpdateEntry.AddNew

rsUpdateEntry.Fields("title1") = Request.Form("title1")
rsUpdateEntry.Fields("body1") = Request.Form("body1")
rsUpdateEntry.Fields("title2") = Request.Form("title2")
rsUpdateEntry.Fields("body2") = Request.Form("body2")
rsUpdateEntry.Fields("title3") = Request.Form("title3")
rsUpdateEntry.Fields("body3") = Request.Form("body3")
rsUpdateEntry.Fields("title4") = Request.Form("title4")
rsUpdateEntry.Fields("body4") = Request.Form("body4")
rsUpdateEntry.Fields("title5") = Request.Form("title5")
rsUpdateEntry.Fields("body5") = Request.Form("body5")
rsUpdateEntry.Fields("image1") = Request.Form("attach1")
rsUpdateEntry.Fields("image2") = Request.Form("attach2")
rsUpdateEntry.Fields("image3") = Request.Form("attach3")
rsUpdateEntry.Fields("image4") = Request.Form("attach4")
rsUpdateEntry.Fields("image5") = Request.Form("attach5")
rsUpdateEntry.Fields("country") = Request.Form("country")
rsUpdateEntry.Fields("dest_url") = Request.Form("dest_url")


rsUpdateEntry.Update

rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
end if
Thanks
Mark

View 1 Replies View Related

Select Null Value Date Fields Record

Sep 28, 1999

Hi:

I used this statement, select * from table1 where date1 = null, in SQL Query window and got a few records back. Now, I used the same statement in my VB 5 code and no record is found. How do I select all the records in table1 which do not have values in field date1? Thanks for the help.

-Nicole-

View 2 Replies View Related

Update If Exist-one Table To Another From Tow Date Fields- Single Row For Each Day

Apr 20, 2008

question need help
how can i use this code below not for insert
i need it for update another table but only if exist
the link to the code in this FORUM
http://forums.microsoft.com/MSDN/AddPost.aspx?PostID=3208536&SiteID=1&Quote=True






Adam Haines wrote:









GPS,



Since you have such a dependency on dates and date calculations, you should implement a calendar table. A calendar table will make calculation such as this much more simplistic.



Calendar table link http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html.

Note the calendar table I use is a little different than this one. The only thing you will need to change is isodate to dt.


Now the code to get the results you need:



Code Snippet
declare @t table(
id int,
fname char(4),
Start_Date datetime,
End_Date datetime,
val_holiday int
)
insert into @t values (111, 'aaaa', '3/15/2008', '03/21/2008', 1 )
insert into @t values (222, 'bbbb', '05/2/2008', '05/9/2008', 3)
insert into @t values (333, 'cccc', '04/3/2008', '05/15/2008', 4)
insert into @t values (333, 'cccc', '04/29/2008', '07/07/2008', 1 )

select id, fname, cal.ISODate, val_holiday
from @t t1

inner join Calendar cal
on cal.isodate >= t1.start_date and
cal.ISODate <= t1.end_date







is possible to do it
TNX

View 4 Replies View Related

Update Fields With Data From Other Fields In Same Row

Jun 30, 2000

Pardon me if this question is too elementary. I am trying to create a trigger that will cause certain datafields to be updated with values from other data fields in the same row when a certain column, created specifically to fire the trigger, is updated. The purpose of this is to reduce data entry by field personnel.I think I have the create trigger statement correct, but I'm a little confused on the update statement.

In a nutshell, how can I write something like:
UPDATE "TABLENAME"
SET DATAFIELD1 = DATAFIELD2
WHERE RECORDNUMBER = (THE SAME RECORD NUMBER)

I do know that I have to ensure that sp_dboption Recursive Triggers value is set to false, thanks.

View 2 Replies View Related

Subreports: Parameter Value Dropdown Shows Sum And Count Fields But Not The Actual Data Fields.

Jan 28, 2008


I have just started using SQL Server reporting services and am stuck with creating subreports.

I have a added a sub report to the main report. When I right click on the sub report, go to properties -> Parameters, and click on the dropdown for Parameter Value, I see all Sum and Count fields but not the data fields.

For example, In the dropdownlist for the Parameter value, I see Sum(Fields!TASK_ID.Value, "AppTest"), Count(Fields!TASK_NAME.Value, "CammpTest") but not Fields!TASK_NAME.Value, Fields!TASK_ID.Value which are the fields retrieved from the dataset assigned to the subreport.

When I manually change the parameter value to Fields!TASK_ID.Value, and try to preview the report, I get Error: Subreport could not be shown. I have no idea what the underlying issue is but am guessing that it's because the field - Fields!TASK_ID.Value is not in the dropdown but am trying to link the main report and sub report with this field.

Am I missing something here? Any help is appreciated.

Thanks,
Sirisha

View 3 Replies View Related

Creating A Table In SQL Server With Fields From Other Tables And Some Fields User Defined

Feb 20, 2008

How can I create a Table whose one field will be 'tableid INT IDENTITY(1,1)' and other fields will be the fields from the table "ashu".
can this be possible in SQL Server without explicitly writing the"ashu" table's fields name.

View 8 Replies View Related

Public Overridable ReadOnly Default Property Fields() As ADODB.Fields

Jan 26, 2008

sir

I have got this error message to establish connction with recordset vb .net, Can you please rectify this

Too many arguments to 'Public Overridable ReadOnly Default Property Fields() As ADODB.Fields'

my code like this


rs = New ADODB.Recordset

rs.Open("Select * from UserLogin where userid='" & txtUserName.Text & "'", gstrDB, DB.CursorTypeEnum.adOpenStatic)


If txtUserName.Text = rs.Fields.Append(userid) Then


MsgBox("OK", MsgBoxStyle.OKOnly, "Confirmation")

End If


thanks

View 1 Replies View Related

Transact SQL :: Get One Row From Multiple Based On Fields And Also Get Sum Of Decimal Fields?

Jul 2, 2015

I am using MS SQL 2012.  I have a table that contains all the data that I need, but I need to summarize the data and also add up decimal fields while at it.  Then I need a total of those added decimal fields. My data is like this:

I have Providers, a unique ID that Providers will have multiples of, and then decimal fields. Here are my fields:

ID, provider_name, uniq_id, total_spent, total_earned

Here is sample data:

1, Harbor, A07B8, 500.00, 1200.00
2, Harbor, A07B8, 400.00, 800.00
3, Harbor, B01C8, 600.00, 700.00
4, Harbor, B01C8, 300.00, 1100,00
5, LifeLine, L01D8, 700.00, 1300.00
6, LifeLine, L01D8, 200.00, 800.00

I need the results to be just 3 lines:

Harbor, A07B8, 900.00, 2000.00
Harbor, B01C8, 900.00, 1800.00
LifeLine, L01D8, 900.00, 2100.00

But then I would need the totals for the Provider, so:

Harbor, 1800.00, 3800.00

View 3 Replies View Related

Q:Duplicate A Record Except One Or Two Specific Fields Using SQL

Oct 30, 2000

Using Transact-SQL how can I copy all fields except one from one record to another? The field in question being the identity field. Since, this field cannot be duplicated a simple INSERT statement fails. How can I specify an exclusion list of fields?

-Sumit

View 1 Replies View Related

Search Multipe Fields, Compounding Fields, Like, Contains...?

Jul 20, 2005

I would like to search a table for a phrase, or for a partial phrase,eg on table product - for name or description, or name + descprition.How does one say select * from product where name + description like%phrase%or contains phraseCurrently I can get where name, or where descriotion like %phrase%,eg, where name like krups, or where description like coffee makerBut if I search for where name like %krups coffee maker% i get noresults. krups is in the name field, coffee maker is in thedescription field.Thanks,-M

View 1 Replies View Related

Easiest Way Of Combining Multiple Fields From Different Records Into One Record?

Jul 20, 2005

I have a table;CREATE TABLE theLiterals (theKey varchar (255) NOT NULL ,theValue varchar (255) NULL)INSERT INTO theLiterals VALUES('defaultServer','\MyServer')INSERT INTO theLiterals VALUES('defaultShare','MyShare')INSERT INTO theLiterals VALUES('defaultFolder','MyFolder')INSERT INTO theLiterals VALUES('defaultFile','MyFile.dat')I then try;SELECTdefaultServer = CASE WHEN theKey = 'defaultServer' THEN theValue END,defaultShare = CASE WHEN theKey = 'defaultShare' THEN theValue END,defaultFolder = CASE WHEN theKey = 'defaultFolder' THEN theValue END,defaultFile = CASE WHEN theKey = 'defaultFile' THEN theValue ENDFROM theLiteralsand I get;defaultServer defaultShare defaultFolder defaultFile\MyServer NULL NULL NULLNULL MyShare NULL NULLNULL NULL MyFolder NULLNULL NULL NULL MyFile.datbut I want it COALESCEd like this;defaultServer defaultShare defaultFolder defaultFile\MyServer MyShare MyFolder MyFile.dat....but my syntax is incorrect. Is there an efficient way of doing this.I want to have a script/UDF where I can say...GetLiteralsFor('defaultServer','defaultShare','def aultFolder','defaultFile')and then my one-row recordset will be...RS(0) will = '\MyServer'RS(1) will = 'MyShare'RS(2) will = 'MyFolder'RS(3) will = 'MyFile.dat'Thanks for any help!

View 5 Replies View Related

Fields Within A Certain Date

Mar 11, 2006

Hello.

I need an SQL Statement for SQL Server in VB.Net that will return values from a table for parts that are due for maintenance within 1 month.

Select * from Part Where DateNOverhaul <= '" & DateAdd(mm,-1,Date) & "' is not working.

I have been trying various solutions on the web and am getting confused because none seem to work. Please help me.

Thank you.

View 7 Replies View Related

SQL Date Fields ASP.NET

Jul 23, 2005

Hello !How to save on SQL server a date in this format?dd-mmm-yyyyAlso, I have a web form in ASP.net and I want the users to enter datesonly in the above format. I am going to need to make calculationsbeased on the above.Many Thanks,Marios Koumides

View 2 Replies View Related

Date Fields

Dec 18, 2007



Im creating a table that links employees to jobs, each employee can only be in one place at once. I have fields for start date and end date. Whats the best way of ensuring an employee cannot be assigned to more than one job at the same time.

Im thinking update/insert trigger that ensure Start Date or End Date being added is NOT >/=existing Start Date and </=existing End Date.

Anyone any better ideas?

Thanks in advance

Alex

View 3 Replies View Related

Is There A Way To Update Multiple Fields Using UPDATE Command

Oct 19, 2005

UPDATE #TempTableESR SET CTRLBudEng = (SELECT SUM(Salaries) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudTravel = (SELECT SUM(Travels) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudMaterials = (SELECT SUM(Materials) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudOther = (SELECT SUM(Others) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudContingency = (SELECT SUM(Contingency) from ProjectBudget WHERE Project = @Project)above is the UPDATE command i am using in one of my stored procedures. I have to SELECT from my ProjectBudget table 5 times to update my #TempTableESR table. is there an UPDATE command i can use which would let me update multiple fields in a table using one SELECT command?

View 1 Replies View Related

Update 10000 Fields

Nov 15, 2007

I have a list of 10000 websites that need to be updated with certain data.

So my question is would i be able to get SQL to lookup a certain list of websites? And then me update the required fields?

Its prob an easy answer, thanks!

View 9 Replies View Related

How To Enable The SQL To Update All Fields?

Nov 9, 2006

How to enable the SQL to update all fields?

"UPDATE addresses SET "

+ "strCompany='" + strCompany + "',"

+ "Name='" + strName + "',"

+ "strAddress='" + strAddress + "',"

+ " strPhone='" + fields.phone.getText() +
"',"

+ " strHp='" + fields.hp.getText() + "',"

+ " strFax='" + fields.fax.getText() +
"',"

+ " strEmail='" + strEmail + "',"

+ " strStart='" +
fields.start.getText().trim() +
"',"

+ " intDay= '" + Integer.valueOf(dd) +
"',"

+ " intMonth='" + Integer.valueOf(mm) +
"',"

+ " intYear='" + Integer.valueOf(yy) +
"',"

+ " strMrc='" + fields.mrc.getText() +
"',"

+ " strIsp='" + fields.isp.getText() +
"',"

+ " strDes='" + fields.des.getText() +
"',"

+ " strSale='" + fields.sale.getText() +
"',"

+ " strContract='" +
fields.contract.getText() +
"',"

+ " strMark='" + fields.mark.getText() +
"'"

+ " WHERE strCompany='" + strCompany

+ "'"
+ "AND strName='" + strName + "'";

View 1 Replies View Related

Find The Newest Date Of 2 Date Fields

Aug 20, 2007

I've 2 date fields clidlp,clidlc in my data base table. How do I find the newest dates between the fields? Thanks for your help!

View 1 Replies View Related

How Do You Sort On Two Date Fields ?

Nov 29, 2006

I am trying to order two date columns. One Ascending theother Descending. I am using the Orders table of Northwind in SQLServer. No idea why, but it only sorts on the first column I setcriteria on. I think you have to convert it to date as it gets storedas date/time...I triedSELECT     TOP 100 PERCENT OrderID, CustomerID, EmployeeID, OrderDate,CONVERT(char(10), RequiredDate, 103) AS RequiredDate,CONVERT(char(10),                     ShippedDate, 103) AS ShippedDate, ShipVia,Freight, ShipName, ShipAddress, ShipCity, ShipRegionFROM         dbo.OrdersORDER BY RequiredDate, ShippedDate DESCBut odd results occuredAny ideas appreciated

View 3 Replies View Related

Merging Date Fields In Sql

Feb 11, 2008

i have two columns in sql which is datetime datatype
fromdate & todate, now i want to display it like fromdate-todate in my front end
select fromdate +'-'+ todate as date from table.
when i use this query , the error is
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Thanks for any help

View 1 Replies View Related

Sorting Of Date Fields

Dec 27, 2004

hi,

When the autogenerate property of datagrid is set to true, how to perform sorting on date fields.

Example:

SELECT DC_NO AS [Document No],CONVERT(CHAR(10),DC_DT,103) AS [Document Date],
[Name] FROM XYZ

Here we convert the date field to the format "dd/mm/yyyy" so when sorting is done it is done in the format "dd/mm/yyyy". But instead sorting should be done in "yyyy/mm/dd" format.

View 6 Replies View Related

Please Help Me Populate My Date Fields

May 7, 2004

Hi,

I have the following table:

CREATE TABLE [Orders] (
[OrdID] [int] ,
[OrderDate] [datetime] ,
[OrderDateONLY] [datetime],
[OrderDayName] [nvarchar] (15),
[OrderMonth] [nvarchar] (25),
[OrderDayOfMonth] [smallint] NULL ,
[OrderWeekofYear] [smallint] NULL
)
GO

The field OrderDate contains BOTH Date and Time information. What I want to do is populate the fields (in bold above) from the OrderDate field... I have tried all that I could think of but nothing works. The last and the best try that I gave was the {B}following[/B] but that too does not work. Can you PLEASE help. Many thanks in advance:


Insert ORDERS
(OrderDateONLY, OrderDayName, OrderMonth, OrderDayOfMonth, OrderWeekofYear)
select
d, datename (dw, d), datename (mm, d), Year (d), datepart (ww, d)
from
(select convert (char (8), OrderDate, 112)as d
from ORDERS
) as x

View 3 Replies View Related

SQL- How To Compare Max Date Across Fields

Jan 4, 2006

Hello, I am wondering how to select the max date from a database view containing multiple date fields for a particular record. I am rusty at SQL and can't seem to get started. Here's an example of the data:

PRCL_IDPROJ_STRT_DTORD_DT ...
1242/3/20063/5/2006
5206/3/20068/2/2006
6412/31/2005
1872/14/20063/16/2006

I need to be able to compare the max date for each PRCL_ID record ("where prcl_id="). In the example above, prcl_id 124 has a max date of 3/5/2006, and prcl_id 520 has a max date of 8/2/2006, etc. The results of the SQL query should return the PRCL_ID and the max date.

Example query results:

PRCL_ID ORD_DT
124 3/5/2006

Please let me know if you can help or if I can provide more info.

Thanks,
Alexkav

View 6 Replies View Related

Comapring Date Fields

Feb 28, 2006

I am trying to compare two date fields; one is a string and one is a getdate() field. I am trying to get them into the same format so I can compare them. What am I doing wrong??? :eek:

select convert(integer, substring(loc_86, 1, 2)) as tmonth,
convert(integer, substring(loc_86, 3, 2)) as tday,
convert(integer, '20'+right(loc_86, 2)) as tyear,
datepart(month, (dateadd(day, -1, (getdate())))) as ymonth,
datepart(day, (dateadd(day, -1, (getdate())))) as yesterday,
datepart(year, (dateadd(day, -1, (getdate())))) as yyear
from ub_chg_tbl join ubmast_tbl
on (ubmast_tbl.patient_nbr = ub_chg_tbl.patient_nbr)
where tmonth = ymonth and tday = yesterday and ty= yyear

View 13 Replies View Related

Please Help Me Populate My Date Fields

May 7, 2004

Hi,

I have the following table:

CREATE TABLE [Orders] (
[OrdID] [int] ,
[OrderDate] [datetime] ,
[OrderDateONLY] [datetime],
[OrderDayName] [nvarchar] (15),
[OrderMonth] [nvarchar] (25),
[OrderDayOfMonth] [smallint] NULL ,
[OrderWeekofYear] [smallint] NULL
)
GO

The field OrderDate contains BOTH Date and Time information. What I want to do is populate the fields (in bold above) from the OrderDate field... I have tried all that I could think of but nothing works. The last and the best try that I gave was the following but that too does not work. Can you PLEASE help. Many thanks in advance:


Insert ORDERS
(OrderDateONLY, OrderDayName, OrderMonth, OrderDayOfMonth, OrderWeekofYear)
select
d, datename (dw, d), datename (mm, d), Year (d), datepart (ww, d)
from
(select convert (char (8), OrderDate, 112)as d
from ORDERS
) as x

View 7 Replies View Related

Nullable Date Fields ?

Dec 7, 2007

Is it bad design to allow nulls on a date field ? I can think of one case such as a sale of an item and populating a field for the date of purchase, only when the purchase took place (and null until then).

comments ?

View 5 Replies View Related

Date Only Fields In SQL Server

Jul 20, 2005

Does anyone know if Microsoft is planning to add a DATE only data typeto SQLServer.I know that you could use a datetime and convert/cast or use datepartto compare, but this can be tedious and error prone.What is the recommended way to compare date-only fields?eg if convert(char(11), @date_field) = convert(getdate(), @date_field)-- do something??

View 3 Replies View Related

Cumulating Fields By Date

Nov 18, 2007

Below is the schema and data for a simple table dat looks similar in structure to what I have.




Code Block
/****** Object: Table [dbo].[cumulative] Script Date: 11/17/2007 17:29:58 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cumulative]') AND type in (N'U'))
DROP TABLE [dbo].[cumulative]
GO
/****** Object: Table [dbo].[cumulative] Script Date: 11/17/2007 17:29:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cumulative]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[cumulative](
[PK] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ID] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[date] [datetime] NULL,
[wear] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[distance] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
END
GO
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'1', N'21', CAST(0x000098B200000000 AS DateTime), N'1', N'10')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'2', N'22', CAST(0x000098B200000000 AS DateTime), N'2', N'11')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'3', N'23', CAST(0x000098B200000000 AS DateTime), N'3', N'23')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'4', N'21', CAST(0x000098B300000000 AS DateTime), N'4', N'22')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'5', N'22', CAST(0x000098B300000000 AS DateTime), N'3', N'32')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'6', N'23', CAST(0x000098B300000000 AS DateTime), N'1', N'12')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'7', N'21', CAST(0x000098B400000000 AS DateTime), N'4', N'15')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'8', N'22', CAST(0x000098B400000000 AS DateTime), N'2', N'17')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'9', N'23', CAST(0x000098B400000000 AS DateTime), N'2', N'10')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'10', N'21', CAST(0x000098B500000000 AS DateTime), N'2', N'8')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'11', N'22', CAST(0x000098B500000000 AS DateTime), N'6', N'9')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'12', N'23', CAST(0x000098B500000000 AS DateTime), N'3', N'11')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'13', N'21', CAST(0x000098B600000000 AS DateTime), N'4', N'24')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'14', N'22', CAST(0x000098B600000000 AS DateTime), N'3', N'5')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'15', N'23', CAST(0x000098B600000000 AS DateTime), N'2', N'34')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'16', N'21', CAST(0x000098B700000000 AS DateTime), N'3', N'12')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'17', N'22', CAST(0x000098B700000000 AS DateTime), N'1', N'12')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'18', N'23', CAST(0x000098B700000000 AS DateTime), N'3', N'13')
INSERT [dbo].[cumulative] ([PK], [ID], [date], [wear], [distance]) VALUES (N'19', N'23', CAST(0x000098B800000000 AS DateTime), N'5', N'14')





I need a sql code that will calculate and create a cumulative wear and distance fields. Im working in SQL server 2005 (sp2).

What I will like to see for the new fields is like:






Cum_Dist
Cum_wear

10
1

11
2

23
3

32
5

43
5

35
4

47
9

60
7

45
6

55
11

69
13

56
9

79
15

74
16

90
11

91
18

86
17

103
14

117
19

Happy thanksgiving!!

View 15 Replies View Related

Using LIKE To Find Any Of Fields In One Table In Fields Of Another

Jul 31, 2013

I have a list of items in one table and a field (pageName) in another table that may contain one of the aforementioned items somewhere within that field. There is no fixed position within the field where the itemNo may be so I can't just use SUBSTRING(pageName,2,5) in(select itemNo from tblItem).

Logically, it's like I need to combine IN and LIKE: select pageName where pageName LIKE IN %select itemNo from tblitemNo%..LIKE can only handle one comparison string.

View 5 Replies View Related

Update Certain Fields From A Grid View ?

Sep 25, 2006

Hi all,I asked a similar question a few weeks ago but I didn't explain myself to well so I was hoping for some more input.I have created a webpage in Visual web developer that contains a gridview that points to an SQL table.All works well as far as searching the table and sorting.  The SQL table itself is Droped ( deleted ) and then re-created every 1 minute from a query to a linked DB2 database  so that we have a "live" table of our DB2 system but in SQL.....However,There is now a requirement to be able to ADD data to this SQL table. eg: a comments field.. from the website.My procedure for re-creating the SQL DB is now useless as any data added through the website would be lost when the table gets re-created.What is the best way for me to achieve a permanent table in SQL that gets updated from the Linked server DB2 but that I can also add comments from the front end (Website Gridview)..I'm assuming some sort of update query and a join to a seperate, permanent table that contains the comments?.Please help. Ray.. 

View 1 Replies View Related

Update Query That Only Updates Certain Fields

May 28, 2006

I'm not a T-SQL expert so I'm calling on the pros. I want to design a stored procedure that updates only fields  in a given record for which a non-null parameter is specified.
Example:
Create dbo.MySproc
   @CustomerID int,
   @CustomerFirstName varchar(50)=NULL,
   @CustomerLastName(50)=NULL
AS
UPDATE Customers
SET
   CustomerFirstName= @CustomerFirstName , //update only if non-null
   CustomerLastName= @CustomerLastName   //update only if non-null
WHERE CustomerID = @CustomerID
RETURN
So say when calling sproc if @CustomerFirstName is specified but @CustomerLastName is not, the field CustomerFirstName would be updated but field CustomerLastName would retain original data.
Thanx in advance!
 

View 2 Replies View Related

Possible To UPDATE Multiple Fields Conditionally?

Nov 14, 2013

I have a am doing some date calcs () . The situation is that I have a Move date (date a customer moved to a new home). I want to calculate their sales for the following 0-3 months after the move (month 0 being the move month). I have the month and year of the move (MthStart, YrStart), and I am adding 3 to MthStart to get the MthEnd of that 0-3 month period. I will then find sales BETWEEN YrStart&MthStart AND YrEnd&MthEnd (there is a YrMth field in the sales table)

Of course, for MthStarts 10, 11, and 12, the ends are 13, 14, and 15. So for these, I need to subtract 12, and increment the YrEnd by 1.

I am wondering if there is a way to update both the MthEnd and YrEnd fields at one time instead of separate SETs (or maybe I am just thinking about this the hard way to begin with). Is there a way to update both in a single CASE statement like WHEN MthEnd> 12 THEN MthEnd-12 AND YrEnd+1?

Code:
CREATE TABLE #myTable (
YrStart INT,
MthStart INT,
YrEnd INT,
MthEnd INT);

[code]....

View 4 Replies View Related







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