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 2008 Forums
 Transact-SQL (2008)
 date conversion help in report

Author  Topic 

ssdeveloper
Starting Member

37 Posts

Posted - 2011-09-07 : 10:55:55
Hi Everyone,

I have this strange situation which I was trying to work around from many days. I have this column with rows entered as string and I was trying to derive a date out of it. Ex: 'lm_na_app_06_08_2010' and substring the date and convert it to dateformat and then use it in some other calculation used as a filter. But the people who put this data in, were not consistent with the dates in the string and there are several issues which couldnot convert the date part and thus stops the proc.

And this proc will be used in the report which takes the tag mentioned above as a parameter. I want to try and catch the error and display the customised message in the report so that the user knows it s the fault with the date in the tag.

How can we put the catch thing in the proc if I know the sql server error message as Msg.241.....

Thanks in advance

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-09-07 : 14:39:00
Have you tried implementing a TRY-CATCH block in your SQL code and utilizing the ERROR_NUMBER() function to determine if your error of interest has occurred?


=======================================
The first rule of Tautology Club is the first rule of Tautology Club. -xkcd, (Honor Societies)
Go to Top of Page

ssdeveloper
Starting Member

37 Posts

Posted - 2011-09-07 : 14:49:18
Yes, It just returns the error number. How can I print custom message when we come across that particular error?
Go to Top of Page

ssdeveloper
Starting Member

37 Posts

Posted - 2011-09-07 : 15:36:38
I know I should use RAISERROR for displaying the new msg but I didn't use the try and catch block before so can somebody help me with the syntax how to put it all together?

Thanks a lot
Go to Top of Page
   

- Advertisement -