Tricky Date Datatype Question

Feb 20, 2008



Hello all,

I have tricky question related to date fields. here i explain with a simple scenario.

Consider a table A with about 100000 patient stay records. the table has facilitypatientkey, staybegineffectivedate, stayendeffectivedate columns. There can a more than one record for a patient since same patient can stay and get discharged more than once. For example


facilitypatientkey stays from '1/1/2000' to '5/25/2000'
facilitypatientkey stays from '12/20/2000' to '3/15/2001'

I want to return the latest end date of each patient. This is pretty straightforward we can just group by facilitypatientkey and return max(enddate) like below

Select facilitypatientkey,maX(stayendeffectivedate) AS MaxEndDate from dw_patient_stay
where facilitypatientkey IN (Select facilitypatientkey from dw_patient_stay)
group by facilitypatientkey
order by facilitypatientkey

but the tricky part is, if the latest end date is 'null' then i want to return as 'null' for that patient.

For example,
facilitypatientkey stays from '1/1/2000' to '5/25/2000'
facilitypatientkey stays from '12/20/2000' to '3/15/2001'
facilitypatientkey stays from '4/12/2007' to null(which actually means they still stay)

now the above query ll return '3/15/2001' instead of 'null'. Can anyone help me with this?

I hope you got the picture.

Thanks,
Praveen


View 5 Replies


ADVERTISEMENT

Tricky Date Manipulation

Sep 2, 1999

Given any date, how can I change that date to be one of the next 3 year cycle dates.
These are the fixed cycle dates (always on Sep 1 on those set years)
9/1/1997
9/1/2000
9/1/2003
etc.

For example,
if the supplied date was January 4, 1998, it would convert to September 1, 2000
October 31, 2000 -> September 1, 2000
Decemb 12, 2005 -> September 1, 2006
January 1, 1995 -> September 1, 1997

Thanx,
Angel

View 1 Replies View Related

Tricky Group By Date Problem

Nov 2, 2006

Hi,I have a tricky SQL query problem that I'm having probs with.I have a table which resembles something like thisDate | Price1 | Price2 | Price301 Jan 2006 | 100 | 100 | 10002 Jan 2006 | 100 | 100 | 10003 Jan 2006 | 100 | 100 | 10004 Jan 2006 | 115 | 100 | 10005 Jan 2006 | 115 | 100 | 10006 Jan 2006 | 115 | 115 | 11507 Jan 2006 | 115 | 100 | 10008 Jan 2006 | 100 | 100 | 10009 Jan 2006 | 100 | 100 | 100and I want to write a query/view that will return this


Quote:

View 15 Replies View Related

Tricky Query, Get Inventory Count By Date Range

Mar 8, 2008

Hi,

My tables:

Product
- productID
- name
- price

Inventory
- productID
- stockCount
- timestamp

So each day the Inventory table has a new row for each productID with its stock count.

How can I create a report for the total products sold from one day to another? Or from what a dateStart from a dateEnd (i.e. a range)

Example:

ProductID StockCount TimeStamp
1 10 2008/03/07
1 7 2008/03/08

So you can see that 3 products were sold in the last day.

View 4 Replies View Related

Date Datatype.

Mar 31, 2007

Is there any datatype only for date....other than datetime....

View 7 Replies View Related

Date Datatype In Sql Problem

May 15, 2008

hi all
i want to know how i can save date in datetime or smaldatetime in this format "dd/m/yyyy" without saving time just date
and how i can use    "select date1 from tbl where a between  c and b" in asp.net to etrive correct field
thanx for all

View 5 Replies View Related

Date - Datatype Error

Jun 1, 2000

In Ms-Access table I have the field called
date which yyyymmdd

the data I have in Ms-Access is

19940101
year month day.

Ms-Access data type is date and ms-Sql datatype is datatime. but still i'm getting error any help

What should be the Ms-Sql data type filed ?

When I try to conver from Ms-ACCESS to MS-SQL Server it give me this error


Server: Msg 8114, Level 16, State 8, Line 1
Error converting data type DBTYPE_DBTIMESTAMP to datetime

View 2 Replies View Related

Date Time DataType

Sep 26, 2002

Here is my delema:
I have data that I have transfered from Access2000 to SQL2000 without issue. However, in my data from Access I have a date field that has just date. When brought into SQL2000 it is given a timestamp as well. According to documentation, if no time is entered in teh field, one is provided (12:00:00 AM).

My delema is that I have a dropdown list box that displays distinct dates from a table for selection to execute a query but now my listbox is twice as long due to the insertion of the timestamp.

Is there a way to get rid of the timestamp that I am not capturing for this field? I can't believe that SQL2000 doesn't have a way to handle just a date.

Thanks for your thoughts.

Tim

View 9 Replies View Related

DATE Datatype Confusion?!@?

Dec 17, 2007

I am having trouble inserting date values into my table. The error is SP2-0552: Bind variable "23" not declared. It is confusing the colons in the DATE datatype with bind variables.


CREATE TABLE event(
e_name VARCHAR2(20) NOT NULL,
c_name VARCHAR2(20) NOT NULL,
descriptionVARCHAR2(110)NOT NULL,
locationVARCHAR2(20)NOT NULL,
begin_dateDATENOT NULL,
end_dateDATENOT NULL,
CONSTRAINT pk_event PRIMARY KEY (e_name),
CONSTRAINT fk_event FOREIGN KEY (c_name)
REFERENCES committee (c_name)
);

INSERT INTO event VALUES ('Pizza Party', 'Marketing', 'Promotes society and free pizza', 'BMU', 31-DEC-2007:21:00:00, 31-DEC-2007:23:00:00);


I thought I was using the standard DATE format, whcich is DD- MON-YY HH:MI:SS


Please help...

View 6 Replies View Related

Order By Date ASC - Datatype Is Datetime

Jan 16, 2015

I have below SQL, which should be order by posteddate ASC

SELECT AnnouncementID,[Subject],[Description],
CONVERT(nvarchar(10),PostedDate,101) AS PostedDate,
CONVERT(nvarchar(10),ExpiredDate,101) AS ExpiredDate,
CountryID,CreatedBy, CreatedDate, ModifiedBy, ModifiedDate
FROM Announcements a
WHERE isActive = 1
AND CountryID = 2
AND (GETDATE()>= PostedDate)
AND (GETDATE()<= ExpiredDate)
ORDER BY PostedDate ASC

But result is displaying as below, PostedDate datatype is datetime

01/01/2015
01/02/2015
12/28/2014
12/31/2014

Expected result is

01/02/2015
01/01/2015
12/31/2014
12/28/2014

View 1 Replies View Related

Date (not Datetime) Datatype In 2005?

Apr 19, 2006

For some reason, I recall having read that SQL Server 2005 would supporta datatype that represented date, but not time. (This would be usefulfor storing things like birthday, where you usually don't care about thetime of day). But I've got SQL Server 2005 installed, and there's nosuch datatype to be found.Is this something that might be released in a Service Pack, or is itjust not going to happen?

View 3 Replies View Related

Problem In Datatype Date Convertion

Mar 20, 2006

Hi,

My source is flat file and my destination is SQL SERVER 2005 using SSIS TOOL.

In my source file i got a date column which is in ISO standards ex: 20050131

I have taken source flat file data type as database date [DT_DBDATE] and in

destination table i declared data type as datetime.

When i start debugging i am getting an error saying that data conversion is not possible.

Can you please help me out how to solve the problem, what data types do i need to take in source and destination and is there any necessity of using Data Conversion Transformation.

If, so please tell me how to do.

With Regards

Satish



View 1 Replies View Related

Is There An Auto Date Datatype For A Field In The Table

Sep 29, 2004

Is there an AutoType Datatype for Date field. just like the Identity property for an ID field.

It increments by 1 for each new record.

The same way if i add a record to the table can it automatically put todays date or date and time for the field date created in my table.

The reason is i am uploading the record from xml file(Using SQLXMLBULKLOAD) so i dont have a chance to mention on the front end code or in the XSD file.

Any help would be greatly appreciated.

View 1 Replies View Related

DateTime Datatype, How To Display Just Date, Not Time

Apr 26, 2006

I have a column with DateTime Datatype. But I want to display just Date , not time.
Like 4/26/2006  not 4/26/2006 9:25:55AM
pls help

View 3 Replies View Related

Grouping By The Date Portion Of A Datetime Datatype

Jul 13, 2000

Hi,

I have a requirement to be able to select and group records by the date portion of a datetime field. ie ignore the time when grouping so that all records lodged on a particular day are seen together.

I have been able to do this by

- converting the datetime data to the number of days since a given date
- inserting this into a temporary table
- retrieving the the data from the temporary table
- convert the data back to a date using DATEPART to display dd/mm/yy

This then gives me the data grouped as required but seems to be a very difficult solution - Is there an easier way??

Thanks in advance
jan

View 3 Replies View Related

Datatype Date As Clustered Index - Next / Previous

Jan 18, 2014

I have a table where the Primary Key is of datatype DATE. This column is also a clustered index. Since not every day is in this column i am looking for a way to address a date one ( or two, or three) Dates before a given date. Something like:

select * from myTable
where [date] = one record previous to record where date = '22-05-2000'

How is that possible.

View 1 Replies View Related

DB2 Date && Time Datatype Migration To SQL Server Datetime

Feb 15, 2006

Hi,

We are migrating our database from DB2 8 to SQL Server 2005. We have date and time saperate columns in DB2. For example, Date_of_birth, Store_sun_open_time, Store_sun_close_time etc. For date we are using datetime. For time what datatype should we use in SQL Server?

Thanks

Prashant

View 3 Replies View Related

Alter Table Datatype Giving Error Date To Bit

Nov 20, 2014

IF EXISTS (SELECT * FROM SYS.COLUMNS WHERE NAME =N'Case_Escalated__c' AND OBJECT_ID = OBJECT_ID(N'[Case]'))
begin
alter table [Case] alter column Case_Escalated__c bit null
print 'Case_Escalated__c altered sucessfully for [Case]'
end

Msg 1792, Level 16, State 1, Line 3
Alter table 'Case' failed because the added fixed column might cause existing data to go beyond the maximum allowable table row size of 8060 bytes.

View 4 Replies View Related

Store Column With Date Datatype In MM/DD/YYYY Format?

Oct 16, 2015

We are on SQL Server 2012 and I was wondering if you store the values in the columns with "date" or "datetime" datatype in MM/DD/YYYY format? Currently I am storing them as Varchar(10) using the Cast &  Convert function to preserve "fomatting" but it would be great to do that in the date/ datetime datatype as well -- is that possible?

Note that this is not for a transnational table but for a data warehouse project. I have three fields in the date dimension each with it's own usage: INT (e.g. 20151016), DATE & VARCHAR.

View 3 Replies View Related

SQL Query - Use Date Format Data And Match It To MS-SQL's Datetime Datatype?

Apr 12, 2007

Need some quick help here.. The data I got from the text file use the "04/11/2007" date format and the StockDate in MS-SQL use the datetime datatype.

My understanding is that the "04/11/2007" will default to the 04/11/2007 12:00 am" format in MS-SQL.

So, when I use the sql query, how do search only for the date part of the data in MS-SQL and match it to the data from text file? I tried this SQL Query below.

--snip--
SELECT RawID FROM tblPurchaseRaw WHERE VIN = '" & sVin.ToString.Trim & "' AND StockDate = '" & dStockDate.ToString.Trim & "'
--snip--

That way, if I get a row then I know the data is there. If I don't get a row then I know the data is not there.

Bold: I get it now. It is all automatic as MS-SQL does it automatically...

View 5 Replies View Related

SQL 2012 :: Datetime To Date Datatype Increasing Index Size?

Mar 6, 2014

I have a database which is centered around two date tables (approx. 5.5 million records each). We are finally making the big leap from SQL Server 2005 to 2012. The data is currently stored as datetime, and we are hoping to take advantage of the new date datatype, since the time component is not needed.

The first table has 13 different date columns. In testing on the 2012 server I have changed 3 columns so far, and have seen that changing the datatype to date is actually increasing the Index size and not affecting the data size. Only 3 of the columns are associated with indexes, and modifying a non-indexed column still increased the index size. I am running the Disk Usage by Table report to view the sizes.

View 3 Replies View Related

Transact SQL :: Based On Data Convert Datatype And Make Wrong Date As NULL

Apr 21, 2015

In the below scenario we are inserting some time related fields in Temp table.But its data type is varchar. Once data loading is finished in the temp table (Data is loading by source team SQOOP and they are unable to load if the source datatype is having Date or datetime) we have to alter the column datatypes. somehow, some character data in inserted in date columns (look at into 3rd insert statement). while altering the table it is failing. Can we do any alternative for this (Means if any varchar data that is non convertible to date can we make as null)

INSERT INTO ##TEMP_TEST
SELECT '2014-09-30','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
UNION SELECT '2014-09-29','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
UNION SELECT '2014-09-28','2017-10-06','Nov  6 2014  6:11AM','Nov  6 2014  6:11AM'
GO
INSERT INTO ##TEMP_TEST SELECT NULL,NULL,NULL,NULL 

[Code] ....

View 6 Replies View Related

T-SQL (SS2K8) :: Varchar Datatype Field Will Ignore Leading Zeros When Compared With Numeric Datatype?

Jan 28, 2015

Need to know if the varchar datatype field will ingore leading zeros when compared with numeric datatype ?

create table #temp
(
code varchar(4) null,
id int not null
)
insert into #temp

[Code] .....

View 4 Replies View Related

Numeric Datatype To Ssis Variable Datatype Conversion Problem

Apr 24, 2008



Good afternoon,

I have an issue with an ssis variable datatype.

The scenario is as follows:

I have a stored procedure:


PROCEDURE [dbo].[sp_newTransaction]



@sourceSystem varchar(50),

@txOut NUMERIC(18,0) OUTPUT

AS

insert into scn_transaction (sourceSystemName) values(@sourceSystem);

SELECT @txOut = @@identity


Whose purpose is to perform an insert into a table and return me the identity value of the inserted record, which I'll then use throughout the rest of my package. The identity column in the inserted table is numeric(18,0).

I execute the stored proc with the following sql with an OLE DB connection manager:

exec sp_newTransaction ?, ?

The first parameter is a string variable from earlier in the package, and the second is the output parameter. I have the following parameter mappings to the execute sql task:

User:ystxId output numeric 1 -1
User:ourceSys input varchar 0 -1

The proc is correctly called, and the row insesrted, however I get a type conversion error when SSIS attempts to map the return parameter to my package variable... I've tried all sorts of combonations, and can't seem to get it to execute.

At one point I wasn't returning a numeric, but rather an int from the stored proc, and all was well until I went to use the variable in a derived column later in the package, and the type was converted quite incorrectly (a 1 was 77799789080 or some such), indicating a type conversion error likely related to the encoding of the number.

I'd like to keep the datatypes as numeric and make ssis use those - any pointers are greatly appreciated as to what type my package variable should be to allow proper assignment of a sql server numeric type to it.

Thanks much,

B

View 6 Replies View Related

Convert Char Datatype To Datetime Datatype

Sep 17, 2003

Database is SQL Server 2000

I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.

What is the syntax to convert char(6) to datetime?

Thank you in advance.

View 1 Replies View Related

Modify Nvarchar Datatype To Datatime Datatype

Mar 14, 2008

Hi,

I imported a table from Accees to SQL 7 with data in it.
I need to modify one of the datatype columns to "datetime" from nvarchar.

I tried to convert it manually, in SQL Server Enterprise Manager tool, but it gave me an error.

I also tried, creating another column "DATE2-datatype:datetime" and updating the column with the old one.

UPDATE users SET DATE2 = DATE.. But it also faild,..

How can I modify the column?

Thank you.

View 10 Replies View Related

Converting INT Datatype To BIGINT Datatype

Dec 15, 2005

HI,I have a table with IDENTITY column with the datatype as INTEGER. Nowthis table record count is almost reaching its limt. that is totalrecord count is almost near to 2^31-1. It will reach the limit with inanother one or two months.In order to avoid the arithmentic overflow error 8115, we would likechange the datatype from INT to BIGINT. we hope this will solve ourproblem.How do I approch this datatype conversion?. Since the data count ishuge, that leads to a long down time of database.we need better approach or solution for this problem?. kindly give mea better solution that will reduce the total downtime of the productiondatabase.?.Regards

View 1 Replies View Related

Text Datatype Vs Nvarchar Datatype

Feb 25, 2008



Hi guys..

i have so doubts in my mind and that i want to discuss with you guys... Can i use more then 5/6 fields in a table with datatype of Text as u know Text can store maximu data... ? acutally i am trying to store a very long strings values into the all fields. it's just popup into my mind that might be table structer would not able to store that my amount of data when u use more then 5/6 text datatypes...

and another thing... is which one is better to use as data type "Text" or "varchar(max)"... ?
if any article to read more about these thing,, can you refere to me...

Thanks and looking forward.-MALIK

View 5 Replies View Related

Tricky SQL - Need Help

Nov 8, 2004

I have 2 tables joined together by the IDs, People and the pets they
own

PEOPLE
ID NAME
1 JohnSMith
2 JaneDoe

PETS
ID PET
1 Dog
2 Cat
2 Hamster
2 Hamster
2 Fish

I have create another where the PETS are in one column separated by
semi-colons and removing the dups

NEW TABLE
ID NAME ALLPETS
1 JohnSmith Dog
2 JaneDoe Cat;Hamster;Fish

What is the best way to do it? The only way I can think of is to run
an update where it checks to see if the value already exists

THanks!

View 1 Replies View Related

Tricky SQL

Mar 18, 2008

Hello,
I have four diffrent tabels:
bo_ Class, bo_Competition, bo_Result, bo_Licence
And list all Licence where bo_Class.classRankingNbr >0

ResultLicNbr FirstName SurName ClassName ResultPlace ClassRankingNbr ClassRankingFemaleMale
------------ --------- --------------- ------------- ----------- --------------- ----------
M70891DEN03 Dennis Vrabac U23 SM 2007 - Herrar 1 1 H
M050887PON01 Pontus Svensson U23 SM 2007 - Herrar 2 1 H
M181188MAR01 Marcus Edlund U23 SM 2007 - Herrar 3 1 H
M190291JOH01 Johan Helldén U23 SM 2007 - Herrar 4 1 H
M180360GER01 Gert Lindholm Herrar klass A 1 2 H
M041062MIC01 Micael Hamberg Herrar klass A 2 2 H
K191286SOP01 Sophia Bergvall U23 SM 2007- Damer 1 1 D
K030889REB01 Rebecka Larsen U23 SM 2007- Damer 2 1 D
K050785CAR01 Carin Johansson U23 SM 2007- Damer 3 1 D

If bo_Class.ClassRowNbr for an Class is 1 get out place 1 from that competition,
and if an ClassRowNbr is 2 get out top2 from that competition.
And so on.

From that list i want an SubQuery list where all licens order by where
bo_Result.ResultPlace = bo_Class.ClassRowNbr.

In text form:

ResultLicNbr FirstName SurName ClassName ResultPlace ClassRankingNbr ClassRankingFemaleMale
------------ --------- --------------- ------------- ----------- --------------- ----------------------
M170891DEN03 Dennis Vrabac U23 SM 2007 - Herrar 1 1 H
M180360GER01 Gert Lindholm Herrar klass A 1 2 H
M041062MIC01 Micael Hamberg Herrar klass A 2 2 H
K191286SOP01 Sophia Bergvall U23 SM 2007- Damer 1 1 D
K030889REB01 Rebecka Larsen U23 SM 2007- Damer 2 1 D
K180793LIN01 Linnéa Hamberg Damer Klass A 1 1 D


Hope someone can take the time and help me out.

Best regards
Gert Lindholm

View 6 Replies View Related

Tricky SQL!

Oct 18, 2005

One statistic questiong from an db Resultat.

SELECT m.Namn + ' ' + m.ENamn AS Spelare, SUM(r.Serier) AS Ser, SUM(r.Poang) AS Po, ROUND(SUM(r.Resultat) / SUM(r.Serier * 1.0), 2, 1)AS Snitt, ROUND(SUM(r.Poang * 1.0) / SUM(r.Serier), 2) AS [P Snitt], ROUND(SUM(r.Miss * 1.0 / r.Serier), 2, 1) AS Miss, SUM(r.Miss) AS [Sa Miss], MAX(r.Resultat) AS Bästa, MIN(r.Resultat) AS Sämsta
FROM Resultat r INNER JOIN
Medlemmar m ON r.Spelare = m.ID
WHERE (r.Omgang IN (SELECT DISTINCT TOP 3 Omgang
FROM Resultat
ORDER BY Omgang DESC))
GROUP BY m.Namn + ' ' + m.ENamn
ORDER BY 4 DESC

What i want to do is sort out Min(r.Resultat) where serier is mor than 3, Not WHERE (r.Resultat) >3. More like in Access "Min(IIf(r.serier=4,r.resultat,Null)) AS [Sämsta]" But that i cant do in SQL

Have also tryed with "WHERE (SELECT MIN(r.Serier) FROM Resultat
Resultat r INNER JOIN
medlemmar m ON r.Spelare = m.ID"
Get lowest result same on all players.

Best reg
Gerten

View 2 Replies View Related

Help With Tricky T-SQL

Feb 7, 2006

Hello allI've got this tricky situation that I would like to solve in SQL, butdon't know how to do. This is the table:Id = 3, VId = 2, Time1 = 10:00, Time2 = 14:00Id = 4, VId = 2, Time1 = 16:00, Time2 = 17:00Id = 5, VId = 2, Time1 = 18:00, Time2 = 19:00Id = 6, VId = 2, Time1 = 20:00, Time2 = 21:00Id = 7, VId = 3, Time1 = 11:00, Time2 = 13:00Id = 8, VId = 3, Time1 = 15:00, Time2 = 16:00Id = 9, VId = 3, Time1 = 18:00, Time2 = 20:00GetRows @Time='15:30' will return row with Id=4GetRows @Time='16:30' will return row with Id=4 and row=9Logic behind this:Return row n where Time2 of Id=(n-1) < @Time < Time 1 of Id=(n) and sameVId.Ie. if @Time = '15:30' then Time2 of Id = 3 is lower than @Time, andTime1 of Id = 4 is higher than @Time => return row with Id = 4.This got a bit messy but if someone could decipher this and possiblygive an answer I'd be very glad.regardsJohnny

View 5 Replies View Related

Here's A Tricky One

Jan 28, 2008

I have an integer in the database that was saved in reverse byte order (BigEndian). Due to some backward compatibility issues (long story) I can't just convert the number to the normal format and save it that way in the database.
Instead, when I read the number in my program, I just reverse its bytes and display the proper value, and translate the number back when it has to be saved back to the database.

Now, the problem is that there are some views that pull this numbers directly from the database and display it.

My question is: can this number be converted from BigEndian to LittleEndian similarly to how I do in my program using T-SQL?

Thanks.

View 4 Replies View Related







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