Sql Server Date Handling

Oct 14, 2007

I have a field in one of my tables called renew_date. The renew_date is always the first of every month. My requirement is to have a query that's run on the first of every month to select records that have renew_date coming up in the next 150 days.(5 months from today).

ANY help is really appreciated.

View 4 Replies


ADVERTISEMENT

SQL Server 2012 :: Handling Odd Date Format

Aug 21, 2015

I need to handle date format "41981".

View 9 Replies View Related

Handling Null Date Values

Jun 30, 2000

I would like some suggestions on how to keep from displaying the value "1/1/1900" on my asp pages when my recordset field returns a Sql date value that is null

Thanks for any tips
Jim

View 1 Replies View Related

Date And Time Handling Abd Validation In SSIS

Nov 22, 2007

I have two columns in Informix data base One has Data Type of date and another column of data type string.
Time is stored in string format. I have to Validate wether both are correct, not null, greater than 1753 and concate to get one datetime field to transfer to SQL Server.
Right now I am doing it in script component, as I need to log error if any thing is wrong
Is there any better way to do it,(derived column or any other component) so that I can log the error also.

Thanks
Dharmbir

View 7 Replies View Related

Handling Server Errors

Sep 10, 2001

Hello,
I want the server to check validation rules and not the user application
is this possible???
I want to send my own messages to the user and dont want the user to see the
servers messages.
Thank you in advance
Eran

View 1 Replies View Related

Error Handling In SQL Server

Apr 26, 2000

How to capture errors occured in stored procedures in case SQL SERVER7?

View 1 Replies View Related

SQL Server Error Handling

Apr 4, 2006

Hi I think by virtue of not being able to find reference to this I have my answer however.... You trap an error, check it and know that you are happy with it - it isn't an issue. Is it possible to prevent that specific error (number, message - the lot) being passed to the client so developers don't need to handle the error a second time? Ta db chucks :D

View 9 Replies View Related

How Well Is SQL Server 2005 Handling Media?

Dec 12, 2006

I'm thinking of storing a lot of images, Word documetns, PDF, and emails as media in SQL Server 2005. Is it equiped to handle a lot of media? Or is it still preferred to store media separately on a file server?

View 6 Replies View Related

MS SQL Server Handling Unicode Data

Feb 21, 2007

Hi,

I want to fetch Unicode data from MS SQL server 2005.I have created one user with russian language characters.

Following is my code snippet:
------------------------------------
wchar_twchar1[55];
char VALUE[255];

while (rc != SQL_NO_DATA)
{
rc = SQLFetch(hstmt);
if (rc != SQL_NO_DATA)
memset(VALUE,0,255);
int length=wcstombs( NULL,(wchar_t *)&wchar1, wcslen(wchar1));
char* strChar = (char *) malloc((length +1 )* sizeof(char));
if (strChar != NULL)
{
count++;
memset(strChar,0, length + 1 );
int i =wcstombs(strChar, wchar1, wcslen(wchar1) );
printf( "i is %d",i);
}
printf( "The length is %d",length);
wprintf(L" <%s>", wchar1);
printf(" simple char <%s>", strChar);
wprintf(L" simple char <%S>", wchar1);
}


-----------------------------------

CAn anybody help me ?
I think problem is in fetching of name.
Does anybody have working code for fetching unicode data from SQL server 2005.

Also I want query that will tell the locale setting of the server and also client?


Thanks-----

View 4 Replies View Related

Exception Handling On Linked Server?

Mar 6, 2009

I am trying to handle exceptions using try catch with remote database.

I am writing the following code which works fine if login locally but when I am trying to do the same on linked server its not being caught in try..catch block.

The procedure I am writing to raiserror

create proc CustomError
as
RAISERROR ('db error', 16, 1);

I am calling the above procedure in local database using following code

BEGIN TRY
exec CustomError
END TRY
BEGIN CATCH
select ERROR_MESSAGE() as ERROR_MESSAGE;
END CATCH;
GO

and it works perfectly. I am able to catch the error in catch block.

and i m getting the following result
db error

but when i am trying to do the same on linked server the code doesn't take me to catch block. I am getting following error while executing the code

go
BEGIN TRY
exec [192.168.0.50].[BM].dbo.CustomError
END TRY
BEGIN CATCH
select ERROR_MESSAGE();
END CATCH;
GO

where [192.168.0.50] is a linked server name and BM is the database name and custom error is my sp which is on remote server.

its giving me following error

Msg 50000, Level 16, State 1, Procedure CustomError, Line 11
db error

View 1 Replies View Related

Sql Server Severity And Exception Handling

May 29, 2007

I'm creating a class that will wrap a SqlException and will offer the developer a way of determining how to proceed in handling the exception by offering a suggestion of retrying, revalidating the data, and/or calling the entire process a no go.

One of the ways i've come up with to accomplish this is by using the severity (SqlException.Class) to assist in making a suggestion to the developer.

I'm hoping to get some feedback from the developers who use this forum if they feel severity is or is not the way to go, and also to offer any other ways of accomplishing that they can come up with.

Thanx

AJ

View 3 Replies View Related

Error Handling W/o Using Cursors In SQL Server 2K

Jan 13, 2008

Hi,

I've the following program structure:

For every record
-- insert into table1
-- insert into table2
....

if I encounter an error in the table1 insert, is there any way (other than using cursors) to continue processing the next record?

Thanks for your help.

Subha Fernando



View 11 Replies View Related

SQL 2012 :: Error And Transaction Handling In Server

May 3, 2015

I'm taking the liberty to announce the availability of a suite of articles on my web site about error and transaction handling in SQL Server. In total there are three main parts and three appendixes.

The first part is a short jumpstart, while Part Two is a long in-depth discussion of what can happen in SQL Server in case of an error and what commands that are available. Part Three covers implementation and has lot of examples as well as a facility for logging and raising errors.

The appendixes cover special areas: linked servers, the CLR and Service Broker.

Start at [URL] ....

View 1 Replies View Related

SQL Server (2005) - SQL Job Steps / Error Handling

Apr 4, 2008

We have several jobs that if any step fails, we need to continue with the next step. Due to this we have the both 'On Success Action' and 'On Failure Action' set to 'Go to the next step'. Our only issue is that when all the steps are done we still require the job itself to fail.

So my question is this, is there anyway the status of a job can be queried to determine if any of it's steps failed?

View 6 Replies View Related

Triggers Error Handling In MS-SQL Server 2000

Oct 24, 2007


We have trigger on a table. The trigger implementation is to insert a record in another table. If any error occurred in the trigger then the trigger should log the error to a file on the file system.

CREATE TRIGGER [myTRIGGER] ON [dbo].[MyTest]
AFTER INSERT
AS
declare @errorcode int;
INSERT INTO MySecondTable (id, myvalue) values (null, 'hey')
set @errorcode=@@ERROR
if (@errorcode <>0)
print 'Error occurred with error code "' + CONVERT(varchar, @@ERROR) + '"'

Problem
If the insert statement fails, for example because of a null violation, then trigger aborts and never reaches the next step in the trigger T-SQL code.
IS this a limitation or there's somthing wrong on the above code?
Thanks

View 6 Replies View Related

SQL Server Bug In Handling Of Getutcdate() During DST Time Change?

Nov 6, 2006

During this latest time change, the value of getutcdate() was offset by one hour as called from SQL Server. True UTC time should never be impacted (or changed) by any Daylight Savings Time activity. This is likely not an OS issue, since IIS logs did show the correct UTC time (unchanging) during the DST time change.

Here is a record of how the time change was handled by a running SQL 2000 sp4 Server as these functions were called:

getutcdate() = Oct 29 2006 5:50AM //ran at the same time as// getdate() = Oct 29 2006 1:50AM

getutcdate() = Oct 29 2006 7:05AM //ran at the same time as// getdate() = Oct 29 2006 2:05AM

@@Version=Microsoft SQL Server 2000 - 8.00.2040 (Intel X86) May 13 2005 18:33:17 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 1)


Thanks -

View 3 Replies View Related

Linked Server Error Handling In Stored Procs.

Jun 29, 2004

I would like to capture any errors thrown by linked server in my stored procedure, How do I do this? eg: Select statement in sp to remote server fails if login credentials were changed for some reason on remote server. @@error is not able to capture this error and stored procedure is terminated when this type of error occurs.

View 1 Replies View Related

DTS Import - Error Handling And Scheduling- SQL Server 2000

Mar 10, 2002

Hi,
I would like to transfer data from an oracle database to SQL server database 2000. I am using DTS Export/ Import Wizard for this purpose.
My queries are:
1. How can I write the write the Start time, End time, data records that failed to a log file with minimal amount of coding. (I found that Active X scripts can be written although the coding is quite complex).
Can I get some kind of pointers to simple coding that can ensure I log time of run of DTS and errors if they occurred.

2. There is an error log written by DTS, but this is written only if an error occurs and the details of error are not written. I am looking to log successful transfers too. Can the DTS package be modified, with minimal code to achieve this objective?

3. I tried scheduling the DTS through the Edit window that SQL Server 2000 provides but am not able to change the time of schedule.
How do I schedule it?


Thanks,
Karthik

View 1 Replies View Related

Formview - Exception Handling A Sql Server Raised Error On Insert

Dec 2, 2005

I'm trying to get to grips with the formview control and have a problem regarding where an exception is raised if SQL server raises an error when an insert is taking place. I am new to both asp.net & c#
I have put the following code in the SqlDataSource2_Inserted & Formview1_Inserted  events as a way of determining where the exception is raised:
if (e.ExceptionHandled){   string exceptionmessage = e.Exception.Message;   lblStatus.Text = exceptionmessage;}
These two events are the only one's that have the ExceptionHandled and Exception properties.
I run the code with data that will raise a duplicate key error from SQL Server but the error is not being caught by either of these two handlers. All I get is a page that starts with
 Server Error in '/SourceCode' Application.


Violation of UNIQUE KEY constraint 'IX_reftblAntigens'. Cannot insert duplicate key in object 'reftblAntigens'.The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'IX_reftblAntigens'. Cannot insert duplicate key in object 'reftblAntigens'.The statement has been terminated....
 Is there somewhere else I should be looking to handle this sort of thing? I thought using the databound controls would make life easier but I'm actually finding it more of a pain than coding everything myself.

View 4 Replies View Related

SQL Server 2012 :: Handling Flat File Destinations Dynamically?

Feb 5, 2015

After performing a join operation on two tables i get the below resultset

pid, fname, typename, pname, pcost

1, cad, bars, product-1, 100

2, har, witte, product-2, 120

3, nes, bars, product-3, 119

Now i need to create files with the obtained resultset like

Column 'fname' is the folder name and 'typename' should be the file in the particular folder.

For example the first record should be inserted into file name 'bars.txt' in the folder 'cad' and third record should be created in file name 'bars.txt' in the folder 'nes'.

View 2 Replies View Related

SQL Server 2008 :: Error Handling In Called Stored Procedures?

Apr 14, 2015

I have one main stored procedure. It calls other 10 stored procedures by giving input parameters.

Do I want to implement Begin Try/Begin catch in each sub procedures or in main procedure only.

View 2 Replies View Related

SQL Server Admin 2014 :: Handling AlwaysOn Failover And Failback To Preferred Node?

Aug 25, 2015

I am running SQL 2014 2-node AlwaysON Availability groups, Enterprise Edition in our environment and 5 databases are part of AG.

Question is, sometimes AG is getting failed over to node2 but always our preferred node is node1 due to some business needs otherwise some of our jobs will fail.

So, what I looking for is, a sql script which can handle a situation wherein, for some reason, AG is failed over to node2, it should be able to detect if node1 is back online or not and if so, it should fail back to node1. How to do this using tsql query or stored proc or sql agent job ?

View 4 Replies View Related

Enable Error Handling When Writing Custom Source Component /custom Error Handling Component.

Apr 21, 2006

1) We are writing a custome Source component for Oracle with OCI calls, Could some one please let me know how to Enable Error Handling for the Same,

2) Is it possible to write Custome Error Handeling Component for SSIS? if yes could you please help me on how to write it.

Thanks in advance.

View 1 Replies View Related

SQL Server 2008 :: Finding Beginning Date From Multiple Lines Of Date Ranges?

Mar 20, 2015

I am trying to find a beginning date from multiple date ranges, for example:

RowNumberidBegin dtEnd Dt
107933192014-09-022015-06-30
207933192013-09-032014-09-01
307933192012-09-042013-09-02
407933192011-09-062012-09-03

For this id: 0793319, my beginning date is 2011-09-06

108203492014-09-022015-06-30
208203492013-09-032014-09-01
308203492012-09-042013-09-02
408203492011-12-122012-07-03--not a continuous date range

For this id: 0793319, my beginning date is 2012-09-04

108203492014-09-022015-06-30

For this id: 0820349, my beginning date is 2014-09-02

To find continuous date, you look at the beginning date in row 1 and end date in row 2, then if no break in dates, row 2 beginning date to row 3 end date, if no break continue until last date There could multiple dates up to 12 which I have to check for "no break" in dates, if break, display beginning date of last continuous date.

View 9 Replies View Related

SQL Server 2012 :: How To Match Two Different Date Columns In Same Table And Update Third Date Column

May 30, 2015

I want to compare two columns in the same table called start date and end date for one clientId.if clientId is having continuous refenceid and sartdate and enddate of reference that I don't need any caseopendate but if clientID has new reference id and it's start date is not continuous to its previous reference id then I need to set that start date as caseopendate.

I have table containing 5 columns.

caseid
referenceid
startdate
enddate
caseopendate

[code]...

View 4 Replies View Related

Transact SQL :: Convert Server Date MM/DD/CCYY To Oracle Date Formatted As NUMBER (8,0)

Apr 30, 2015

So I have to build dynamic T-SQL because of a date parameter that will be provided. The Date Parameter will be provided in SSRS in normal MM/DD/CCYY format. So how do I then convert that date to my Oracle format

NUMERIC(8,0) CCYYMMDD?

I tried this...

SET@SQLQuery=@SQLQuery+'ANDMEMBER_SPAN.YMDEFF<='''''+CAST(@AsOfDateASVARCHAR)+''''''+@NewLineChar;
SET@SQLQuery=@SQLQuery+'ANDMEMBER_SPAN.YMDEFF>='''''+CAST(@AsOfDateASVARCHAR)+''''''+@NewLineChar;

but that put it in the format of...

AND
MEMBER_SPAN.YMDEFF<=''2015-04-01''
AND
MEMBER_SPAN.YMDEFF>=''2015-04-01''

Which is close...I think I just need to lose the "-"

View 5 Replies View Related

Flat File Text Date Conversion To SQL Server Date Comments And Suggestions

Mar 12, 2008

Hi,
Basically the above is a very common requirement, please comment on my solution which I've arrived at by searching through the web; -

In summary I have used 3 SSIS components these are "Flat File Source", "Derived Column" and "SQL Server Destination".

1) File Connections Manager Editor
1.1) Within File Connections Manager Editor; -
Name the data type e.g. "INTERCHANGE_NET_APP_DATE_SRC"
and assign a type to the data type e.g. string[DT_STR]

1.2) Click on the Preview button to ensure the expected text is assigned to the expected data type.


2) Derived Column Transformation Editor
2.1) Assign Derived Column Name, e.g.
INTERCHANGE_NET_APP_DATE

2.2) Select <add as new column> within Derived Column.

2.3) Enter the conversion Expression, e.g. ; -
2.3.1)
(SUBSTRING(INTERCHANGE_NET_APP_DATE_SRC,8,2) + "/" + SUBSTRING(INTERCHANGE_NET_APP_DATE_SRC,5,2) + "/" + SUBSTRING(INTERCHANGE_NET_APP_DATE_SRC,1,4))

2.3.2)
Since the above conversion is such a common task I suggest that Service Pack 3 of SQL Server 2005 delivers the following functionality; -

STRINGTODATE ('YYYYMMDD',INTERCHANGE_NET_APP_DATE_SRC)

2.4) Select "database timestamp [DT_DBTIMESTAMP] " as Data Type.

2.5) Within the Mappings tab of the SQL Destination Editor have; -
Input Column as INTERCHANGE_NET_APP_DATE and
Destination Column as INTERCHANGE_NET_APP_DATE.

Please comment on the above, I will then pass on my suggestion to Microsoft.

Thanks in advance,

Kieran.

View 1 Replies View Related

Problem Inserting Integers And Date In A Sql Server 2005 Datatable Row And Selecting It Afterwards Based On The Date

May 4, 2007

Hi,
 
I have soma ado.net code that inserts 7 parameters in a database ( a date, 6  integers).
I also use a self incrementing ID but the date is set as primary key because for each series of 6 numbers of a certain date there may only be 1 entry.  Moreover only 1 entry of 6 integers is possible for 2 days of the week, (tue and fr).
I manage to insert a row of data in the database, where the date is set as smalldatetime and displays as follows:  1/05/2007 0:00:00 in the table.
I want to retrieve the series of numbers for a certain date that has been entered (without taking in account the hours and seconds).
A where clause seems to be needed but I don’t know the syntax or don’t find the right function
I use the following code to insert the row :
 
command.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime, 40, "LDate"));
command.Parameters[6].Value = DateTime.Today.ToString();
command.ExecuteNonQuery();
 
and the following code to get the row back (to put in arraylist):
 
“SELECT C1, C2, C3, C4, C5, C6 FROM Series WHERE (LDate = Today())?
 WHERE LDate =  '" + DateTime.Today.ToString() + "'"
 
Which is the correct syntax?  Is there a better way to insert and select based on the date?
 
I don’t get any error messages and the code executes fine but I only get an empty datatable in my dataset (the table isn’t looped for rows I noticed while debugging).
Today’s date is in the database but isn’t found by my tsql code I think.
 
Any help would be greatly appreciated!
 
Grtz
 
Pascal

View 5 Replies View Related

SQL Server 2012 :: Calculate Number Of Days Based On Computer System Date And Due Date Row

Mar 18, 2014

I have a query to run a report where the results has a column named “Due Date” which holds a date value based on the project submission date.Now, I need to add 4 columns named, “45 Days Expectant”, “30 Days Overdue”, “60 Days Overdue” and “90 Days Overdue”.I need to do a calculation based on the “Due Date” and “System (I mean default computer date) Date” that if “System Date” is 45 days+ to “Due Date” than put “Yes” in “45 Days Expectant” row.

Also, if “Due Date” is less than or equal to system date by 30 days, put “Yes” in “30 Days Overdue” and same for the 60 and 90 days.how to write this Case Statement? I have some answers how to do it in SSRS (Report Designer) but I want to get the results using T-SQl.

View 2 Replies View Related

SQL Server 2012 :: Script To Specify Date Field To Use For Activity Date

Jun 2, 2014

I'm writing a view to check record counts in a table that has numerous datasets and therefore various "Activity Dates". Is it possible as part of the SQL statement to have a CASE statement for example so that it can identify the field to use as the activity date?

The field to use is being identified using a seperate table so at the moment I have CASE WHEN FieldToUse = '2' THEN MapCol ELSE '[Activity_Date]' END, where FieldToUse = '2' identifies the date field to use and the MapCol data is the field name to be used as the activity date.

Is this even possible?

View 3 Replies View Related

Sql Types - Simple SQL Server Queries/handling Variable Types

May 26, 2005

SQL Server 2000, ASP.Net 1.1

I've been writing this stuff for a while, and can't seem to come to the
conclusion of how I should be retrieving data and assigning this data
to variables.

Since i'm using SQL Server, I'm convinced that I should be using the
datareaders GetSqlDouble (or whatever) function, but this would mean i
need my local variables to be one of the SQL types.  The problem
with that is, that there will have to be lots of conversions done by me
to be able to use a SQL type in my application.

For instance, I have a class where i'm retrieving dates.  In order
to retrieve them correctly (Null values included), I need to retrieve
them with GetSqlDateTime(), then when it comes time to display the date
in a table, i must first check for nulls, then convert to a
string.  This seems to be very cumbersome.  Would I be better
off just using GetDateTime(), and the .ToString method, and ignoring
Sql Types all together?

so, basically, how are you guys using your sql server data?  with
the supplied sql types, and doing all of the post-processing work
manually?  I feel like i'm having trouble conveying my
issue...hopefully someone knows what i mean....i'd just like some
direction to save trouble in the long run, since i feel like there's
got to be a better way...

Confused!

Thanks,
JJ

View 1 Replies View Related

How To Get The Current Date In C# And How Do I Pass This Date To SQL Server

Apr 22, 2007

I am writing a ASP.NET C# web application. I will need to store the date in one field in one of my tables. It appears that I need to use the datetime data type for the date in SQL Server 2005.
So I have a question
1.) How do I get today's date in C# and how should this be passed to SQL server?

View 7 Replies View Related

SQL Server 2008 :: How To Get A Year Ago Date From The Particular Date

May 15, 2015

I have a list of students who have taken a test on different dates.

I need a function to calculate year ago date from the date of test.

eg Sam took the test on feb 23 2015

I need to get a feb 23 2014 to see what subjects he studied from feb 23 2014 to feb 23 2015.

How can I do that.

View 3 Replies View Related







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