Dealing With Empty Datetimes?

Apr 20, 2007

What methods work for storing empty dates? I've read that some people pick an old date and use it to represent empty. I'm not fond of the idea, because then I'll have to strip that date whenever I display the field in my UI.



Any other ways to do this? I'm using SQL Server 2005 and C#.



Thanks!

View 4 Replies


ADVERTISEMENT

How To Tell DB Not To Store Datetimes In 24 Hr. Fo

Apr 11, 2007

There's gotta be a way to tell a DB not to store datetime fields as 24 hour format but rather standard time notation.

So, I don't want this: 2007-04-11 02:01:31.000

I do want this: 2007-04-11 02:01:31 AM

This has to be possible but I can't find it.

Thanks!



--PhB

View 4 Replies View Related

Compare Datetimes

Jul 23, 2005

HiI need to retrieve data from a table comparing datetimes. I mean I've atable with a datetime data and I'll need to retrieve rows with date time[color=blue]> now and date time < now + 5 minutes...[/color]Is this posible ? Which is the best / easy way ?Thanks in advanceJ

View 2 Replies View Related

Issue With Log Shipping Datetimes

Sep 17, 2007

nations_document_sts_20070917144501.trn

9-17 9:45:01 am

Has anybody else noticed this

View 1 Replies View Related

Query List Of Datetimes For Same Date

Jul 7, 2007

Hi:I have created a table that has a column of smalldatetimes.  For any given day, there may be different records with the same date but with different times.  I've created the query SELECT Event FROM Events where Start=@Start and I input start as a selected date from the calendar control.  Because of the different times, I do not get any matches.   Could someone help me with a query that will get all of the events on the same day? Regards,Roger 

View 2 Replies View Related

Joining Records With Nearest Datetimes

Mar 19, 2013

How would I match datetimes in records structured as follows:

Code:
Record1 AccountNo StartDateTime EndDateTime
1 1234 4/30/2012 8:00 AM NULL

2 1234 NULL 5/15/2012 8:00 AM

Desired Result:

Code:
AccountNo StartDateTime EndDateTime
1234 4/30/2012 8:00 AM 5/15/2012 8:00 AM

Of course there are multiple accounts, about 2100 in this case but they very by time periods, and multiple start and stop dates for an account. I need to get the start times and match them w/ the nearest end times but AFTER the value of the start time. Nearest end times must be forced to correspond to the nearest start time but there are some start times w/o end times and end times w/o start times due to user data entry errors. I need a solution that handles this. It is ok w/ the customer to make the assumption of nearest times supposedly going together so they can show the users the errors. I am on SQL Server 2008 R2.

View 4 Replies View Related

Appending Two Datetimes Which Were Converted From Strings

Nov 21, 2006

can anyone teach me how to append to datetime data into one.the first is a date and the 2nd one is a time.the time is converted from string.thanks

View 4 Replies View Related

Converting Integer Values To Datetimes

May 23, 2006

We have inherited an appointments database that has a table tblAppointments

Within this table there are 2 fields, ApptFrom & ApptTo, these are the appointment start & finish times.

My problem is, the values in these fields are held as integers ranging from 0 - 288. I have worked out the scale for the integers, it is based on a 24hr clock with each segment representing 5mins

Eg: 0 = 0:00

12 = 1.00

24 = 2.00

36 = 3.00



...

288 = 24:00

What I need is a piece of T_SQL that will translate these into times that can be read by a normal user

So, say I have a record with an ApptFrom = 36 & ApptTo = 42, I need to be able to show these as ApptFrom = 3.00 & ApptTo = 3.30

Any help is greatly appreciated.

Cheers,
Craig

View 6 Replies View Related

Comparing To DateTimes In SQL-Select-Statement When One Date Can Be Null

Aug 25, 2007

Hello! I have a field "End" in my database that is mapped as DateTime and allows nulls. Now I want to do a SQL-Select (in a SqlDataSource) like SELECT * FROM My_Table Where (([End] = @EndDate) OR ([End] = null))  @EndDate is a valid DateTime, but the second OR condition doesn't work. What is the best way to check if the [End]-field is empty or null? Thank you very much! 

View 1 Replies View Related

Calculate Durations From Start/stop Datetimes (was Reporting...)

May 2, 2006

gday, how do i see what i wanted to see

View 2 Replies View Related

SQL 2012 :: Calculating Elapsed Time Between Datetimes For Travel?

May 20, 2014

I have a requirement to be able to calculate the transit time between international locations when I have the flight departure time and flight arrival times and departure and arrival locations.

We have a problem though, in that the datetime stored are local times, and the journeys can involve crossing the international date line in either direction, so it is possible for the arrival time to be earlier than the departure time!

To give a famous example, if you flew Concorde from London to Washington, you could depart at 10am on the 1st of June (London time) and arrive at 8.00am on 1st June (Washington time)

Even worse, you could leave Brisbane at 2.00 am on the 1st June, cross the International Date Line and arrive at San Francisco at 23:00 on 31st May!

View 6 Replies View Related

Dealing With DBNull

Jan 10, 2008

Hello!
Is there an easy way to deal with this situation below when reading in data from a SQL Database:
int? myNullableColumn;myNullableColumn = Convert.ToInt32(datarow["datacolumn"]);
 
Where, ideally, 'myNullableColumn' would be 'null' if the value was 'DBNull.Value'.  This does not work because Convert.ToInt32 will not convert 'DBNull.Value to null', but instead throws an error.
Is there a built in funtion that does do this?
Thanks!

View 8 Replies View Related

Dealing With Dups And A Lot More!

Mar 14, 2008

Ok, I have a table with about 47000 records in it. I have the following query for that table:Select ReportType =
Case
When ReportType = 1 Then 'Uniquery Report'
When ReportType = 2 Then 'SABRE Report'
When ReportType = 3 Then 'Menu Report'
Else Null
End,
ReportNameTo_,
Frequency.Frequency as Frequency,
ReportDate,
ReportDescription
From Report
Inner Join Frequency on ( Report.ReportFrequency = Frequency.FID )
Where ( Active = 1 )
And ReportDate = ( Select Max ( ReportDate ) From Report Where ( Active = 1 ) )
And ReportID = ( Select Max ( ReportID ) From Report Where ( Active = 1 ) )  
The idea is that i need to get only the last report based off of unique reportname. I added a computer column to the table to give me the ReportNameTo_, since my deliminator is the _. Now my issue is that I have 1 records showing (the last record added to the table), which is right for the query that is written, but wrong for what I want. I need to only return the last record for each unique ReportNameTo_. So as an example, my table has the following ID, ReportNameTo_, Date fields the data looks something like this:
1, 123_, 1/1/20082, 123_, 1/1/20083, 124_, 1/1/20084, 124_, 1/1/20085, 125_, 1/1/20086, 125_, 1/1/20087, 126_, 1/1/20088, 126_, 1/1/2008
I only want to return the following:
2, 123_, 1/1/20084, 124_, 1/1/20086, 125_, 1/1/20088, 126_, 1/1/2008
Hope someone out there can let me know how to do this... I am almost there, just not all the way.

View 2 Replies View Related

Dealing With Duplicates

Feb 15, 2002

Hello!
Just looking for advise on dealing with duplicates in database.
I have a contact table that have a bunch of duplicated customer records.
My goal is to combine all duplicated records into one record.
This involves couple tables:contact,contact history ,calendar.
All tables related by common column "accountno".
What would be the best approach for this?

Thank you,
Lena

View 2 Replies View Related

Dealing With Nulls

Mar 15, 2002

I have the following query in a stored procedure. If there are no rows in the history file, it returns a null. If there some setting or function that would have it return a zero if no rows are found? I use the variable to do arithmetic later on and a null messes everything up.

select@MarketTotal = sum(isnull(MarketValue,0))
fromhistory
whereEmpUID = @EmpUID and
Shares > 0

Thanks,
Ken Nicholson

View 2 Replies View Related

Dealing With NULLs

Jun 9, 2006

Hi i have the following :

select agent, name, surname, address, cust1_text01, cust1_text02, phone1,
case call_type_id
*when NULL then ''
else call_type_id
end as 'call_type_id'
from Record_T

* I have also tried when NULL then space(1)

yet the query still returns NULL when this field is empty ?
the idea is to always return data, even if the field is NULL to
replace it with an empty space or spaces.

View 3 Replies View Related

Dealing With Two Databases

Sep 28, 2007



Hello,

Question 1:
In my senario i've developed a system which utilizes 2 database, i've writen queries like db1.dbo.table1 join db2.dbo.table2 etc... Now that db2 is getting huge, client wants to shift it to another server.
I don't know how to modifiy my queries to cope with such situation. Could somebody plz tell me on how to you write queries involving two databases from different servers.

Question 2:

I'm maintaining second database (db2) to keep track of records of db1 which have been processed by my software, so that when db1 gets added with more records i can compare db2 table with db1 table to identify which records are new.
db1 is not my database and i don't have any control over that, (it's some erp db), is there any way of identifying which rows have been processed. Can the need for db2 be eliminated?


I'm using SQL Server 2005

Thank You,
Sandeep.

View 1 Replies View Related

Dealing With Null Values

Jul 31, 2006

hi ive got a inert sub where i grab values from text boxes etxthe values are passed to a stored procedure however , one of these fields is a date field , but the field is not required ...so on this line if the date text box is left blank i get an error , not a valid date    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Texti have tried ( the actiondate field can take nulls ..)if txtActionDate="" then    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = nothing else.Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Textend if but this doesnt workwhat is the best way of allowing blank values to be passed to the stored procedure( it doesnt fall over with normal text / varchar fields ) thanks

View 1 Replies View Related

Dealing With Datetime And SQL Transact-SQL

Apr 4, 2007

I am trying to make a stored procedure in SQLServer Express.The question is related to this stored procedure / transact - sql.  I think i am doing something wrong with datetime.Here is the stored procedure.The error i am getting is that:Msg 241, Level 16, State 1, Line 20Syntax error converting datetime from character string.  ===================================== DECLARE    @websiteID  intDECLARE    @dateFrom  datetimeDECLARE    @dateTo  datetimeDECLARE    @sortbystring  varchar (20)set @websiteID = 1set @dateFrom = Convert(datetime, '2007-02-07 12:01:00')set @dateTo  = Convert(datetime, '2007-03-07 11:59:00')set @sortbystring = 'Campaign'IF ISNULL(@dateTo, '') = ''begin    SET @dateTo = @dateFromendSET @dateTo = DATEADD(d, 1, @dateTo)DECLARE @str CHAR(400)LINE 20: SET @str = 'SELECT dateEntry, c.name as Campaign, e.firstname as FirstName FROM entry e, campaign c WHERE e.campaignID = c.id ' + 'AND c.websiteID = @websiteID' + 'AND (ISNULL(' + @dateFrom + ', '''') = '''' OR e.dateEntry BETWEEN '' + @dateFrom + '' AND '' + @dateTo + '') ' + 'AND e.IP NOT IN (SELECT IP FROM IP) ' + ' ORDER BY dateEntry DESC'print (@str)=============================================== 

View 9 Replies View Related

Questions Dealing With Performance

Dec 16, 2004

I have a stored procedure that takes less than 1 second in sql query analyzer to return my results.
I run this same SP in ASP.NET using a calendar control and using perf monitor I notice that for me from my dev machine my cpu utilization is sometimes over 40%.Is there any tweaks I can do to help decrease CPU utilization.

View 2 Replies View Related

Dealing With Optional Variables

Jan 23, 2004

I'm looking for opinions here:

I have a stored procedure that has one required variable, and two optional variables, like this:

CREATE PROCEDURE sp_tariff_rule
@tariff_id INT,
@start_date DATETIME = NULL,
@end_date DATETIME = NULL
...etc...

I want the procedure to process
1) all data is no dates are presented
2) all data after the start date, if no end date is supplied
3) all data before the end date if no start date is supplied
4) all data between the start and end dates if both are supplied

Now, instead of an elaborate conditional, I added this to the WHERE clause of my SQL statement:

AND ((@start_date IS NULL OR service_date >= @start_date) AND (@end_date IS NULL OR service_date <= @end_date))

It works fine, but I want to know if anyone has a different/better way of doing it, or if there is a big bug waiting to happen here.

I typically don't like to create multipurpose routines in my code, but this is a better approach for my in a non-object-oriented world of SQL.

View 1 Replies View Related

Dealing With More Than 8000 Characters

Nov 14, 2005

In SS 2000 it seems that there is no variable data type that can hold more than 8000 characters (varchar) or 4000 unicode characters (nvarchar). I've seen posts where multiple variables are spliced together to extend this limit. I am looking at performing string manipulations in an sproc and I need to be able to deal with the full 2GB/1GB limit of text and ntext field types. Is this possible? How do you deal with that?

View 14 Replies View Related

Dealing With 's In Insert Statements

May 31, 2007

Hello all. Got bit of a long winded question here...........so here we go lol.

OK.......ive got data on an Excel spreadsheet. Ive set the spreadsheet up as a linked server and i'm creating a set of insert statements from it by using the following code:


SELECT 'INSERT INTO TRAINREC (COURSE_NAME) VALUES ('''+
EMPLOY_REF + ''', '''+

FROM AtriumDD...['Employee Training Records$']


For most records this generates a correct insert statement.........for example:


INSERT INTO TRAINREC (EMPLOY_REF, COURSE_NAME) VALUES ('153', 'NMA Panel');


However.........my problems start when the value for course name is containes an ' character. If it does the insert statement generated is incorrect. For example:


INSERT INTO TRAINREC (EMPLOY_REF, COURSE_NAME) VALUES ('139', 'Annual Accounting in Lloyd's Market');


can anyone suggest any ideas on how to get round this? Also if i havent explained it clearly enough just let me know and i can try and expand on it.

Thanks for reading.

View 5 Replies View Related

Dealing With A Null Parameter In SP

Jul 20, 2005

I have a stored procedure as a recordsource from a contacts table. Inthis example, users can enter parameters to limit contacts by firstletter of last name or company name or keywords:Example:@myName nvarchar(30) = null,@Alpha char(1) = nullSELECTContacts.ContactID, ContactType,CASE WHEN Contacts.ContactType = 0THEN Contacts.CompanyNameELSEisNull(Contacts.LastName,'?') + ', ' +isNull(Contacts.FirstName,'?')ENDAS CNAMEFROMContactsWHERE(Keywords Like '%' + @myKeyword + '%' OR @myKeyword is Null)So far, so good, but...The problem is I want to also give the user the option of filteringalphabetically by first letter. I can't figure out how to deal withnulls in this example (user doesn't enter anything as parameter@Alpha):AND(@Alpha = CASE ContactType WHEN 0 THEN Left(LastName,1) ENDOR@Alpha = CASE ContactType WHEN 1 THEN Left(CompanyName,1) END)Any help is appreciated,LQ

View 2 Replies View Related

There Has Got To Be A Way To Do This - Dealing With Bad Rows In A File

Apr 3, 2007

Hi,



I just realized something. In the old DTS package I am migrating, there is an ActiveX script that checks for a certain condition in a row. If the condition is true, then it does:



DTSTransformationStat_SkipRow



I just can't believe there isn't an equivalent functionality in SSIS.



However, so far, I have tried the following:



1.) Redirect file error output (on all columns in the file)



2.) Use a conditional transform to search for a text string in a column (the "bad" row has different text in it)



And still, I keep getting errors that there is an "impartial row" in the file. Yes, I know that - why doesn't the error redirection catch this? Why doesn't the conditional expression catch it either?



Am I missing something here? Is it just buggy? I find it hard to believe I have to work around something that worked just fine in DTS.



Thanks





View 26 Replies View Related

Dealing With Latency Issues

Jul 17, 2007

hi,



I'm building a C# database application that access a remote sql 2005 database. For the moment I am using sql express edition. My application will be running in several REMOTE camps which only have an internet connection via sattelite. The sattelite connection has a very high latency. I am wondering what workarounds or solutions are available for this situation. All applications need to access the same database and preferebly be notified when changes take place on the database.



Thanks in advance.

View 1 Replies View Related

Dealing With Dates And Null Values

Apr 2, 2007

Hi EveryoneVery new to .net and currently dipping my toes in the water with a small application, but getting to the point -
I have a form which has somel text fields that expect a date but which are not a required field so in other words the user can leave them blank.
The code behind page stores the information using a stored procedure which I add parameters to in the following fashion -
SqlParameter userdate = new SqlParameter();userdate .ParameterName = "@dtdate";userdate .SqlDbType = SqlDbType.DateTime;userdate .Direction = ParameterDirection.Input;userdate .Value = dtdate.Text.ToString();cmd.Parameters.Add(userdate);
Now if I leave the text field dtdate blank I receive an error because the above expects a date.
If I remove the line userdate .SqlDbType = SqlDbType.DateTime; I don't recieve an error but my stored procedure saves the date as 01/01/1900 or similar.
I believe this is because in my stored procedure the paramger dtdate is defined as @dtdate datetime
Obviously I want to have it so that if the user leaves the text field empty then no date is saved in the database and was wondering how other people tackle this scenario.

View 3 Replies View Related

Dealing With MS SQL Tables That Contain Duplicate Rows

Jan 30, 2008

Hello,
I have a question, i loaded 2 files into SQL and the files have some cells that have the same model number.
how can I merge the cells together that have the same model number and (if possible take the avarage of their cell called price) 
(and combine their other cell called stock)
and make it into one cell.
Any help would be very very apriciated. Thank you. 
i tryed this but it does not work
SELECT Model_number FROM Products
Join Where Model_number='3CM3C1670800B'
I have also Tryed this, IT SHOULD work but I have an error someWhere:
delete from Productsfrom part_number a join
(select part_number, max(part_number) from part_number group by part_number having count(*) > 1) b
on a.part_number = b.part_number and part_number < b.part_number

View 3 Replies View Related

Dealing With CDATA Returned By Sql Server

Jan 18, 2004

I am using SQL Server to return a XML result set. I then perform a XSLT transformation on the returned result set to fill in HTML form text and select elements. The data returned includes the & character. This character correctly transforms, however I believe that the & is negatively impacting my form post (one of the form elements disappears from the posted data). How can I get around this?

View 1 Replies View Related

Dealing With Null On Database Lavel

Feb 22, 2005

Hi
post a sample code
create table testNull(
a int not Null,
b varchar(5),
c varchar(5) )

insert into testNull (a,b,c) values(1,'Alex','test')
insert into testNull (a,b) values(2,'Alex2')



1. select * from testNull
-- return 2 rows
2. select * from testNull
where
a <> 3
and
b <> 'C1'
and
c <>'C2'
-- return ONLY 1 ROW !!!
3. select * from testNull
where
a <> 3
and
b <> 'C1'
and
isNull(c,'') <>'C2'

query 2 will retun only 1 row, because value of column c is Null

Question
Is any setting could be changed on db or server level to prevent errors with missing row in 2-nd query , or I have use isNull operator for every column acepting Null as value ?

View 1 Replies View Related

Dealing With A Result Set From A Stored Procedure

Feb 20, 2004

Hi,
I have a problem with dealing with result sets returned from stored procedures.

I have a procedure like:
CREATE PROCEDURE SampleProcedure
AS
BEGIN
SELECT * FROM SampleTable
END
GO

By executing this stored porocedure is returned result set containing data from SampleTable table. (EXECUTE SampleProcedure)

The returned resultset can be seen in Query Analyzer and can be handled from ADO.NET without any hesitate.

But I can't use this result set from other stored procedure. I tried:
SELECT * FROM (EXEC SampleProcedure)
But there is sintax error in select statement.

Does anybody know, how to store the result set into a teporary table or select it by SELECT statement?

Thanks.
MarF.

View 5 Replies View Related

Dealing W/ Minutes In DateTime Field

Apr 16, 2004

If I subtract 14 days from a datetime field, will the time of day that I run this query affect the resultset? I am running the query during "normal business hours", 8 am - 5 pm, and the records are entered during this time frame as well.

ddave

View 6 Replies View Related

Dealing With Numbers In Text Field

Mar 29, 2015

I have run into a problem when searching for a Movie title that is a number (like the movie name 21)

This is an access database and the Movie_Name is a text field

The SQL I am using is

Select * from Movie_Data where Movie_Title = ‘” & Movie_Name & “’”

This works perfectly for everything except when the Movie_Name = a number

Is there a way to make this search work with both characters and numbers?

View 3 Replies View Related







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