473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Ignore Error in SP

Is there a way to make a SP ignore an error?

e.g. I'm looping through each database on a server, checking of a table
exists then selecting a value from that table. Now I have a database put
onto the server where the table exists but all column names are
different, my SP is not interested in this database so when it errors
with invalid column name I want it to move onto the next databse and not
display any error message.
Jul 20 '05 #1
2 3356

"Trev@Work" <no.email@please> wrote in message
news:41***********************@news.easynet.co.uk. ..
Is there a way to make a SP ignore an error?

e.g. I'm looping through each database on a server, checking of a table
exists then selecting a value from that table. Now I have a database put
onto the server where the table exists but all column names are different,
my SP is not interested in this database so when it errors with invalid
column name I want it to move onto the next databse and not display any
error message.


No - you can't trap errors in MSSQL, you must pass them to the client:

http://www.sommarskog.se/error-handling-II.html

Without more information on what you're trying to do, it's hard to say what
the best solution is, but one option is to test if the column you're
interested in exists:

IF EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '???'
AND COLUMN_NAME = '???'
)
BEGIN
-- DO SOMETHING WITH THE TABLE
END
ELSE
BEGIN
-- MOVE TO NEXT DATABASE
END

Simon
Jul 20 '05 #2
Simon Hayes wrote:
"Trev@Work" <no.email@please> wrote in message
news:41***********************@news.easynet.co.uk. ..
Is there a way to make a SP ignore an error?

e.g. I'm looping through each database on a server, checking of a table
exists then selecting a value from that table. Now I have a database put
onto the server where the table exists but all column names are different,
my SP is not interested in this database so when it errors with invalid
column name I want it to move onto the next databse and not display any
error message.

No - you can't trap errors in MSSQL, you must pass them to the client:

http://www.sommarskog.se/error-handling-II.html

Without more information on what you're trying to do, it's hard to say what
the best solution is, but one option is to test if the column you're
interested in exists:

IF EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '???'
AND COLUMN_NAME = '???'
)
BEGIN
-- DO SOMETHING WITH THE TABLE
END
ELSE
BEGIN
-- MOVE TO NEXT DATABASE
END


I'm actually identifying the database as belonging to a particular
application, we have a simple profiles table that will have a signature,
e.g.

select [value] from zstblProfile where [key] = 'AppSignature'

This is so I can loop all databases and display a list of databases to
the front end's login screen (only dbs applicable to the FE app).

The exist code above will help, thanks.

Unless there's an easier way to stamp a database?
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Bartkus | last post by:
The meaning of REPLACE INTO is clear to me. IF the new record presents new key values, then it is inserted as a new record. IF the new record has key values that match a pre-existing record, then...
5
by: Chris Mantoulidis | last post by:
Let's say I have this: std::string s1; std::cin >> s1; This will read s1 from cin until it finds a space (or a newline, whichever comes first). Okay this works. But when I want to continue...
1
by: windandwaves | last post by:
Are you allowed to use the following syntax in Mysql 4.0.17-nt : INSERT DELAYED IGNORE INTO `mytable` ( `ID` , `A` , `B` ) VALUES ("'.session_id().'", "2", ROUND(NOW()/10000) ); I am...
23
by: FrancisC | last post by:
#include <stdio.h> int file_copy( char *oldname, char *newname ); int main() { char source, destination; printf("\nEnter source file: ");
4
by: Jackson Miller | last post by:
I notice that postgres does not support IGNORE. I am currently migrating an app from a MySQL datastore to Postgres, and I would really like to use IGNORE. I am curious if there is a...
5
by: ma740988 | last post by:
Consider the source: # include <iostream> # include <string> # include <fstream> # include <vector> # include <sstream> using namespace std;
6
by: sandy | last post by:
I seem to ALWAYS need to use cin.ignore in my programs (console apps using Dev C++ for a University course). The problem is that if I don't ignore ENOUGH characters then it's like not having the...
2
by: Sanjaylml | last post by:
I have made a form, in which following two Run Time Errors occured, which ultimately, after clicking Debug button, goes to coding of the form: 1) Runtime error 6 "Overflow", if no data exists. 2)...
1
by: Nimral | last post by:
Hi folks, is there a smart way to develop efficiently that helps me in the following situation: a sub calls a subsub, which calls a subsubsub, and so on. Within a subsubsub an error occurs...
4
by: shodan | last post by:
Hi board, I'm using excel vba to drive my access database. Now I encountered the following problem: I have an update qry to update a table which has an index field. Because of this, I always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.