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


ADVERTISEMENT

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

Re-populate A Unique Number Into Multiple Fields

Oct 14, 2004

What I need to do is re-populate a unique number into multiple fields,

Let me explain, An employee can appear in the first table only once but can be in the second table multiple times with multiple employee numbers .There is a field called TFN that is unique and we are using it to create a unique id called KRid so what I have done is created 2 tables namely TEST_TBL and TEST2_TBL . In TEST_TBL I am populating a KRid with a unique no being produced by the TFN field only once i.e 12345 being the resulting unique id number. If an employee has 2 employee numbers i.e empno 1 and empno 1000,only employee no 1 will have the unique KRid created but nothing for 1000 because the record already exists , so what has me stumped is that the TFN for employee empno 1 and the TFN for empno 1000 are the same. How do I get the KRid (12345 from empno 1) to populate empno 1000 in TEST2_TBL , The second table has all records in so I can group the second table by TFN id but how do I populate employee 1000 in the second table with the KRid 12345.


Please help!!!!! Below are how the tables are set up and an example of the result.

TABLE 1

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TEST_TBL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TEST_TBL]
GO

CREATE TABLE [dbo].[TEST_TBL] (
[Empl_Num] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Surname] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[First_Name] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Mid_Name] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Hours_Day] [numeric](18, 2) NULL ,
[Hours_Wk] [numeric](18, 2) NULL ,
[KR_ID] [bigint] IDENTITY (1, 1) NOT NULL ,
[TFN] [char] (32) COLLATE Latin1_General_CI_AS NULL ,
[Date_Term] [datetime] NULL ,
[Empl_Type] [int] NULL ,
[Cost_Centre] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Empl_Status] [int] NULL
) ON [PRIMARY]
GO

TABLE 2

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TEST2_TBL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TEST2_TBL]
GO

CREATE TABLE [dbo].[TEST2_TBL] (
[EmpNumber] [char] (32) COLLATE Latin1_General_CI_AS NULL ,
[TFN] [char] (32) COLLATE Latin1_General_CI_AS NULL ,
[KR_ID] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
[EmpStatus] [int] NULL ,
[EmpType] [int] NULL ,
[CommonName] [char] (32) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO

Query goes as follows for table 1:

SELECT NPE000.EmpNumber, NPET00.RecordStatus, NPE000.KR_ID, NPE000.Surname, NPE000.FirstName, NPE000.SecondName, NPE000.Class, NPE000.DateEmployed, NPE000.DateOfBirth, NPE000.HoursPerDay, NPE000.HoursPerWeek, NPE000.PassportNo, NPE000.AwardCode, NPE000.EmailPayslipTo, NPE000.Location, NPE000.Grade, NPE000.DateTerminated, NPE000.EmploymentType, NPE000.DistCode, NPE000.EmpStatus, NPET00.TaxRefNo FROM NPE000 NPE000, NPET00 NPET00 WHERE NPET00.RecordStatus = 0 and NPET00.TaxRefNo <> ' 111111111' and NPET00.TaxRefNo <> ' 000000000' AND LENGTH(NPET00.TaxRefNo) >= 9 AND LENGTH(NPE000.KR_ID) >= 0 AND NPE000.EmpNumber = NPET00.EmpNumber


Query goes as follows for table 2:

SELECT NPE000.EmpNumber, NPE000.FirstName, NPE000.Surname, NPE000.Class, NPE000.Location, NPE000.EmploymentType, NPE000.EmpStatus, NPET00.TaxRefNo, NPE000.Paypoint, NPE000.KR_ID, FROM NPE000, NPET00 WHERE Recordstatus = 0 and (EmploymentType = 1 AND EmpStatus = 1 AND NPE000.EmpNumber = NPET00.EmpNumber


From this you can see that in table 1 it will only create 1 KR_ID for only one employee number but in table 2 I am bringing through all employee records. In table 2 I can group by NPET00.TaxRefNo which will bring all NPET00.TaxRefNo's togeather. From that I would like to populate the other employee numbers with the unique KR_ID.

Example:Table 1

000001,Jackson,James,Sam,7.6,38,12345,475431212


Example:Table 2

000001,Jackson,James,Sam,7.6,38,12345,475431212
001000,Jackson,James,Sam,7.6,38,,475431212

I hope this helps

Thanks in advance

View 10 Replies View Related

Need CASE Statement(s) To Populate 5 Fields Based On Values Of 2

Mar 10, 2008

I need to, ultimately, create a flatfile for exporting insurance information to a third-party vendor. Each individual is to have no more than 1 line per file, which contains their coverage information, if any, on 4 different type of insurance. What i need is for 2 fields in a table to determine the output for multiple fields in the flatfile.

What I have so far works, to an extent. If I have insurance types 1, 2, 4 (of types 1-4) required output is (__ = 2 blank spaces):



1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E

== == == == == == == == == == == == == == == == == == == ==

Y N __ MD XX Y N __ MD XX N __ __ __ __ Y N __ DN XX



If they have coverage, A always = Y, B always = N, C always = blank(null), D is their ins. type, E is their cov. type(CASE statement). if they DON'T have that type of coverage, A always = N and the remaining field are NULL.



After a lot of work, and scouring a forum or 2, I attempted a whole lot of CASE functions. Below is an sample of code representing the 1x statements. This same code is repeated 4 times with the 1x being altered with 2x, 3x, 4x.



CASE HB.PLAN_TYPE

WHEN '10' THEN 'Y'

ELSE 'N' END AS 1A,

CASE HB.PLAN_TYPE

WHEN '10' THEN 'N'

ELSE ' ' END AS 1B,

' ' AS 1C,

CASE HB.PLAN_TYPE

WHEN '10' THEN HB.BENEFIT_PLAN

ELSE ' ' END AS 1D,

CASE HB.PLAN_TYPE

WHEN '10' THEN (CASE WHEN HB.COVRG_CD ='1' THEN 'XX'

WHEN HB.COVRG_CD ='2' THEN 'YY'

WHEN HB.COVRG_CD ='3' THEN 'ZZ'

ELSE 'WW' END)

ELSE ' ' END AS 1E,



It works to an extent. While the desires/required output it above, the output this produces (same scenario) is:



1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E

== == == == == == == == == == == == == == == == == == == ==

Y N __ MD XX N __ __ __ __ N __ __ __ __ N __ __ __ __



1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E

== == == == == == == == == == == == == == == == == == == ==

N __ __ __ __ Y N __ MD XX N __ __ __ __ N __ __ __ __



1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E

== == == == == == == == == == == == == == == == == == == ==

N __ __ __ __ N __ __ __ __ N __ __ __ __ Y N __ DN XX



While there is supposed to be 1 line, regardless of number of insurance types, it only produces 1 line per type. I first tried this in Access, and was able to get it to work, but it required multiple queries resulting in a crosstab, export to Excel and manually manipulate the data, export to text file to manipulate, import back into Excel to manipulate, import back into Access and finally export into a flatfile. Far too much work to produce a file which is why I'm trying to convert it to raw SQL.
Any assistance in this matter would be greatly appreciated.

View 5 Replies View Related

How To Populate Fact Table With Date Id From Date Dimension

Dec 28, 2007

can someone help me with th best way to look up a date in date dimension and populate the date id in fact.
in the source date is dd/mm/yyyy
and in date dimension columns are date id , year , quarter , month, day

View 11 Replies View Related

Automatically Populate Application User Defined Field Based On Other Fields In Table

Nov 22, 2015

I am working with a vendor application called Cisco Unified Attendant Console - it operates on a Windows server with a SQL express database. The CUPs function of the application needs to reference a "contact" field with only the user portion of the contact's email address - generally, the contact's User ID will match the user portion of their email address, however, for this customer it does not (they use the employee number as the User ID and firstname.lastname as user portion of the email address.

Writing a script to accomplish the following:

The dbo.Contact_Properties table of the ATTCFG database has the following fields that we can work with:
 
- First_Name
 - Last_Name
 - Email
 - User_Field_2
 - Contact_Unique_Ref (appears to be the field that ties all other contact tables together ?)

Is it possible to create a script that could run daily to either, combine the First_Name and Last_Name fields (with a period between) and populate the User_Field_2 field for each user, or populate the User_Field_2 field with everything before the @ symbol in the Email field for each user?

Also, by default the servers that this application is installed on does not have SQL Server Management Studio installed - is it possible to accomplish with PowerShell script triggered from the Windows Scheduler?

View 5 Replies View Related

Update Fields With Searched First Date Record Fields

Jul 23, 2005

Hello !I'm trying to update one table field with another table searched firstdate 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 caseDROP TABLE TEST1DROP TABLE TEST2CREATE 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 TEST1INSERT 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 TEST2INSERT 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 dataTEST1CUST_CD BOOKING_DATE BOOKPHONE_NOC12005-04-08 21:46:47.78011111111C12005-04-13 21:46:47.78022222222C12005-04-18 21:46:47.78044444444C12005-04-19 21:46:47.78033333333TEST2CUST_CD ENTRY_DATE FIRSTPHONE_NOC12005-04-03 21:46:47.800C12005-04-05 21:46:47.800C12005-04-14 21:46:47.800C12005-04-15 21:46:47.800DESIRED RESULTCUST_CD ENTRY_DATE FIRSTPHONE_NOC12005-04-03 21:46:47.80011111111C12005-04-05 21:46:47.80011111111C12005-04-14 21:46:47.80044444444C12005-04-15 21:46:47.80044444444*/

View 3 Replies View Related

Finding Max Date And Populate New Column

Jan 7, 2014

Aim – Find the latest #Account.[Last_Post_Date] for the Fdmsaccountno and populate the latest date for that Parentid. In a new column Called “Parent Last Post Date"

Current results
FdmsaccountnoParentidLast_Post_Date
87802012188487823334288920140105
87802012788187823334288920140103
87802012888987823334288920131231
87870180988087823334288920131217
87802012088687823334288920131204
87823334288987823334288920131201
87870180888287823334288920131130
87802011588687823334288920131120
87875705088487823334288920131011

Desired results
FdmsaccountnoParentidLast_Post_DateParent Last Post Date
8780201218848782333428892014010520140105
8780201278818782333428892014010320140105
8780201288898782333428892013123120140105
8787018098808782333428892013121720140105
8780201208868782333428892013120420140105
8782333428898782333428892013120120140105
8787018088828782333428892013113020140105
8780201158868782333428892013112020140105
8787570508848782333428892013101120140105

My query is

select
#Account.Fdmsaccountno,
#Account.Parentid,
#Account.[Last_Post_Date],
from #Account
inner join [Dim_Outlet] on #account.FDMSAccountNo = [Dim_Outlet].FDMSAccountNo
where #Account.Parentid = '878233342889'
order by [Last_Post_Date] desc

View 3 Replies View Related

Scipt To Populate Date Dimension?

Mar 7, 2007

Hi Folks,

Can anyone recommend a script to populate a date dimension such as that described in Kimball's "The Data Warehouse Toolkit, 2nd Edition" pp.38-41???

Thanks - wg

View 2 Replies View Related

Detect New Files And Populate Date

Apr 28, 2007

Hi, I need to create a SSIS package for following usage:



I have a folder called c: est. Every month, I copy a file with following format testMMYY.txt. (Month Year) from a client (A) for vendor B. I have a sql table which contains filemonth(, clientname and vendorname. How can I create a SSIS package to detect any new files, if any, and populate the month and year into file month, and populate clientname and vendorname.



Thanks,

View 4 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

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

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

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

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

DTS - Clean Up Date Fields Upon Insertion

Feb 4, 2003

I am importing Visual FoxPro (6) views into SQL 2000 tables and I am looking for a snippet of code to "clean up" date fields upon insertion. I can insert the views into the SQL tables fine using the tables/views selection of DTS as my source. However, I would like to ensure the date fields are in fact vaild dates and not garbage using the SQL query option of DTS source. I would like to do the insert and cleanup in one step. Do you have a snippet of code to validate a date field that I can use? Thank you for any assistance in advance, Terry.

View 3 Replies View Related

BETWEEN With Date/Time In Separate Fields

Apr 22, 2008

My group is working on a project for school and neither of us have much experience with SQL or ASP. We are pretty much just writing an SQL query to get the data in a certain date range and using ASP to write the tables with the data in it.

Our problem is the SQL database has separate fields for date and time. There is nothing we can do about this because the VB.NET program that populates the tables automatically does this. We can't figure out how to do the BETWEEN statement when they are separate fields. We can do it for a date range and it works fine. An example of what we want to do is show the data from 11:00 am on 04/01/2008 until 4:00pm 04/03/2008.

Does anyone have any idea what we can do? I really want to learn this but it's frustrating because we can't seem to get much help at school.

View 5 Replies View Related

Creating A String From Date Fields

Jul 20, 2005

I have a table with a startdatetime and an enddatetime column such as:StartDateTime EndDateTime what I want to see returnedis:01/29/2004 10:30AM 01/29/2004 1:30PM "1/29/2004 10:30AM - 1:30PM"01/29/2004 10:30AM 01/30/2004 1:30PM "1/29/2004 10:30AM - 1/30/20041:30PM"01/29/2004 10:30AM 01/30/2004 10:30AM "1/29/2004 10:30AM - 1/30/200410:30AM"Maybe someone has accomplished this aready in a stored procedure andhas an example of how to do it?lq

View 2 Replies View Related

Importing Null Date Fields

Nov 27, 2006

I'm using SQL Server Express and am trying to import a CVS file. The CVS file contains a string field (named DAS) that represents a Date. This field can be null.

I've tried using the DTS Wizard to import this CVS file and convert the DAS field to a Date, which works great until it hits a record with a NULL DAS field. It then throws a convertion error.

Still using the DTS Wizard, I've changed the DataType of the DAS field in the Source file to [DT_DATE], it works fine but all the null dates are converted to 12/30/1899.

Is there a way (DTS Wizard or something else) that will allow me to import these CVS files with null Date fields and keep them as null in SQL Server table.

Thanks for any help,

Jon

View 4 Replies View Related

Prorating The Date Fields With Cost

Jun 19, 2006

Hi all
I have got 3 columns in my table- start date,finish date and cost..in the
following format...

start_date finish_date cost
12/12/2000 20/12/2000 $2000
01/09/2000 12/10/2000 $400

Now if the month and year of the start and finish date is same, the cost
remains same...
but if the month of the two dates are different, i have to distribute the
cost between the two months by calculating the cost for the number of days
for both of the months..
but i am not able to figure out how?
i am using sql 2005 ..
my table has got about 1 million rows...
pls help.....dll is as followsGO
CREATE TABLE [dbo].[DSS](
[Service Start] [datetime] NULL,
[Service End] [datetime] NULL,
[FMIS Code] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL,
[Client NHI] [nvarchar](255) COLLATE Latin1_General_CI_AS NULL,
[No of Units] [float] NULL,

) ON [PRIMARY]

View 5 Replies View Related

Is It Possible To Save Single Date To A Samlldatetime Fields ?

May 29, 2007

Hi,All:
      I am using Sql 2000 db to storage my data,and I have a table including a column named  "ScanDate" (Type: SmallDateTime),Now
 I just want to save the current system date to this column when I save my system data.
     when I saved it and I found that column value include the time data,not  only date .
    So How can I just save date to my samlldatetime typed column ?
 thanks in advanced!

View 1 Replies View Related

Concatenating Three Longint Fields Into A Date Field

Apr 20, 2001

Good afternoon one and all,

I have the following problem that I can use some help with :

I have a table in a linked server that has the date stored in three fields (i.e. day,month and year (I have no idea why)). I would like to concatenate these three fields together into a datetime format in a SQL statement

Something like

SELECT ([stc_dd] & '/' & [stc_mm] & '/' & [stc_yy]) AS stkdate

(the above line does not work)

Hope that is clear, thanx in advance for any and all help

Gurmi

View 1 Replies View Related

UNION With A Max On Split Date/Time Fields

Mar 30, 2000

I have 2 tables, each with one ID field, a separate
Date and Time fields and a number of other fields.
The tables contain duplicates on the ID field.
I want to do a UNION keeping only the record with the latest
Date and Time.

This would work:
SELECT MyTab.myKeyField, Max(MyTab.myDate) AS myDate
FROM (SELECT myKeyField, myDate
from Table1
union
SELECT myKeyField, myDate
from Table2) AS MyTab
GROUP BY MyTab.myKeyField

But is only taking care of Date, not Time (some records have
the same date but different times)
The other problem is, when I add more fields, I have to
include them in the GROUP BY clause, and this way I end up
with duplicates (because some other fields have different
values)

Is there a way to do this?

View 1 Replies View Related

Finding &#39;null&#39; Date Fields With Query?

Apr 19, 1999

I know I am missing something basic, here.
I have a date field in a table. The field is 'allowed Nulls'. When a certain thing happens in the program, the date is filled in.
At various times, I need to do a query to find all the rows that have no dates entered.

What do I use in my where clause? SQL server does not like 'where date = null.'

Thanks,
Judith

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

SQL Query Syntax To Format Date Fields

Oct 21, 2005

Hi! Good Day!

What is the syntax to format the datefield? The value of my datefield is like this:

10/13/2005 5:15:02 PM

What is the select query to filter the date only. My desired result should be:

10/13/2005

only.

Thanks :)

View 5 Replies View Related







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