Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Exception handling

Author  Topic 

Werwolf13
Starting Member

7 Posts

Posted - 2004-06-01 : 12:14:40
Is there any exception handling mechanism in t-sql simillar to the C# or javascript one for example? (I mean smth. simillar to the try/catch constraction) if no... is there any other way to handle it?

X002548
Not Just a Number

15586 Posts

Posted - 2004-06-01 : 13:30:54
Conversation already in progress...

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=35642

What type of error do you want to handle...




Brett

8-)
Go to Top of Page

Werwolf13
Starting Member

7 Posts

Posted - 2004-06-01 : 14:12:30
One of all tasks is i want to handle date conversion (but not only -- its just one case). I have a table EVENTS with a field DATE of varchar type. In some records the value of this field is correct and amounts to smth like this: 05132004 i. e. mmddyyyy (without separation). But not all of them are correct... some of them can be of such sort: 051 . When i "parse" the string (with SUBSTRING function etc.) i form the string 05/13/2004 for example and its ok to convert it into datetime. But 05/1/ is not convertable and exception raises. You can tell me that I can handle it checking whether the string is correct or not before converting, but its not a good way (moreover, as i have told before, there are variety of such tasks, not only date conversion...). It would be very cute to use smth. like
try { and to place conversion here...}.
Using of @@error does not match, because exception raises anyway and my whole application will not work...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-06-01 : 14:46:59
Sounds like a good job for a User Defined Function...


or

DECLARE @x varchar(8)
SELECT @x = '20040531'

SELECT CASE WHEN ISDATE(@x) = 1
THEN SUBSTRING(@x,5,2)+'/'+ SUBSTRING(@x,7,2)+'/'+ SUBSTRING(@x,1,4)
ELSE '01/01/0001'
END



But why not handle it in the fromt end?

Also, why is the date varchar?

You've already seen data integrity issues...

What other types of conversion you talking about?



Brett

8-)
Go to Top of Page
   

- Advertisement -