Have a database that I restored from a backup on a new sandbox server. I ran a very innocuous update statement:
UPDATE insurance
SET plan_text='MS MEDICAID'
WHERE insurance_id=168331
I received the following error:
Msg 4121, Level 16, State 1, Procedure insurance_track_rev_type1, Line
70 [Batch Start Line 0] Cannot find either column "master" or the
user-defined function or aggregate "master.dbo.GetHashGuid", or the
name is ambiguous.
I changed the ID, the new statement is as follows:
UPDATE insurance
SET plan_text='MS MEDICAID'
WHERE insurance_id=168334
I received the following:
(1 row affected)
I have no idea what is going on. Any ideas?
JG
Related
I am preparing Microsoft SSIS Certification. In the exercice Practice_5-Loading Data: the code provided by the training kit Exam 70-463 doesn't work.
Error message:
Msg 121, Level 15, State 1, Line 3 The select list for the INSERT
statement contains more items than the insert list. The number of
SELECT values must match the number of INSERT columns.
Error message:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'GO'.
Need some help.
Concatinate the two columns (C.FirstName, C.LastName) as fullname.
Thanks
Sasi
I finally find the problem. they were different structure between tables I created and the loading from table... primary key was different and 'curent flag' data type need to have default value set to 1.
thanks for your help
sagbo
I am trying to set up transaction replication on a database. I use the following script to do so:
USE [Archive_MRPa_801]
GO
EXEC sp_replicationdboption #dbname = N'Archive_MRPa_801', #optname = N'publish',
#value = N'true'
GO
USE [Archive_MRPa_801]
GO
EXEC [Archive_MRPa].sys.sp_addlogreader_agent #job_login = N'vrc\S_PSSJ_DWDBN01',
#job_password = '*****', #publisher_security_mode = 1, #job_name = NULL
GO
When I run the first script, it succeeds. When I run the second script I get the following error:
Msg 14013, Level 16, State 1, Procedure sp_MSrepl_addlogreader_agent, Line 38
This database is not enabled for publication.
I am doing the same thing on 2 other databases and these two scripts succeed on them. I am wondering what the error is talking about, not just the solution. Also, the other two databases have a Master Key and this one does not. So, I chose to give a '0' (zero) to the #publisher_security_mode parameter. This gave me the same result as with a '1' (one). I look forward to any responses on this.
Transaction Replication Msg 14013, Level 16, State 1, Procedure sp_MSrepl_addlogreader_agent, Line 38
What Edition of SQL Server is Archive_MRPa_801 on?
SQL Server 2008 R2
I have a table called room_table
room_no room_status room_type
-------|-----------|----------
1001 | A |single
1002 | A |single
1003 | B |single
I am using following code in CICS COBOL program but I am getting SQL error code -811
select room_no
from room_table
where room_status='A'
and room_type ='single'
fetch first 1 row only
I have used cursor concept too but it returns error code -311
Any idea?
This would of been answered before but:
Use a cursor and only fetch the first record, see Cursor
Use group by
Select min(room_no) from room_table
where room_status='A' and room_type ='single'
group by room_status
Did you try using DB2 Fetch-first-clause?
replace select first 1 row only with fetch first row only
-311 is not -811 : Something is wrong with a host variable.
For -811 we would "fetch first row only".
Now,
prior to this feature being available, many coders ignored IBM's warnings and simply allowed -811 as OK, as a value was somehow always returned (albeit without guarantee). I would hope that any such code has long been touched up.
I want to drop a column called id which is an auto incrementing PK.
The SQL:
alter table "CO88GT"."XGLCTL" drop column id cascade;
And I get:
Error: [SQL0952] Processing of the SQL statement ended. Reason code 10.
SQLState: 57014
ErrorCode: -952
I could be wrong but I think it has something to do with preventing the table from losing data. To get around this issue I need to create a new table without the column and copy the data from the old table into the new table and then replace the old table with the new table.
Info
AS400 is giving you a warning (inquiry message) because of possible data loss, asking you to Cancel or Ignore the requested operation. So, beacuse of this being a interactive request, over JDBC/ODBC you cannot type 'I' to ignore, and AS throws you an ErrorCode: -952 with SQLState: 57014 and Reason code 10.
In the documentation of SQL0952 says:
Message Text: Processing of the SQL statement ended. Reason code &1.
Cause Text: The SQL operation was ended before normal completion. The reason code is &1. Reason codes and their meanings are:
* 1 - An SQLCancel API request has been processed, for example from ODBC.
* 2 - SQL processing was ended by sending an exception.
* 3 - Abnormal termination.
* 4 - Activation group termination.
* 5 - Reclaim activation group or reclaim resources.
* 6 - Process termination.
* 7 - An EXIT function was called.
* 8 - Unhandled exception.
* 9 - A Long Jump was processed.
* 10 - A cancel reply to an inquiry message was received.
* 11 - Open Database File Exit Program (QIBM_QDB_OPEN).
* 0 - Unknown cause.
If you are using JDBC and the SQL error isn't self-explanatory, you can make a JDBC connection with parameter 'errors=full', which will give much more info on the error. For other connection parameters see this.
example connection string:
jdbc:as400://serverName;libraries=*libl;naming=system;errors=full;
With that connection the resulting error would be like this:
Error: [SQL0952] Processing of the SQL statement ended. Reason code 10.
Cause . . . . . : The SQL operation was ended before normal completion.
The reason code is 10.
Reason codes and their meanings are:
1 -- An SQLCancel API request has been processed, for example from ODBC.
2 -- SQL processing was ended by sending an exception.
3 -- Abnormal termination.
4 -- Activation group termination.
5 -- Reclaim activation group or reclaim resources.
6 -- Process termination.
7 -- An EXIT function was called.
8 -- Unhandled exception.
9 -- A Long Jump was processed.
10 -- A cancel reply to an inquiry message was received.
11 -- Open Database File Exit Program (QIBM_QDB_OPEN).
0 -- Unknown cause.
Recovery . . . : If the reason code is 1, a client request was made to cancel SQL processing. For all other reason codes, see previous messages to determine why SQL processing was ended.
SQLState: 57014
ErrorCode: -952
The solution
So finally, if you cannot use STRSQL, another solution is to use iSeries Navigator, to be exact its "Run SQL scripts" (it is usually here --> "%Program Files%\IBM\Client Access\Shared\cwbundbs.exe").
But first of all you have to add a system reply parameter (only once per machine)
ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I')
This is done in "green screen". This sets a deafult answer ('I') on CPA32B2 inquiry message. The CPA32B2 is an internal massage id, which is tied to an drop column operation.
(It actually doesn't have to be done in "green screen", use it like CHGJOB command. Example :
cl: ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I');
)
Now you can start "Run SQL scripts", the first command to run is:
cl: CHGJOB INQMSGRPY(*SYSRPYL);
this changes the current job parameter INQMSGRPY, to *SYSRPYL. *SYSRPYL causes to look if exists a system reply parameter when an inquiry message should be displayed.
Now you can run your alter which drops the column.
Unfortunately, I don't know how to drop a column, just using JDBC. If someone knows please let me know.
References:
Understanding What Controls the Automatic Reply Function
Replying to Run-Time Inquiry Messages
Error in dropping column (forum post)
How can I avoid SQL0952 on ALTER TABLE?
Finally I found a solution:
CALL QSYS2.QCMDEXC('ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY(''I'')');
CALL QSYS2.QCMDEXC('CHGJOB INQMSGRPY(*SYSRPYL)');
ALTER TABLE <tablename> DROP COLUMN <column_name>;
There isn't enough information in your error message to be sure, but dropping a primary key column is generally quite risky and the database correctly makes it difficult.
You likely have a foreign key constraint involving that column.
Don't drop the constraint and delete that column unless you're sure you know what you're doing.
According to this post: http://bytes.com/topic/db2/answers/185467-drop-column-table
It is possible to drop a column using STRSQL in the green screen environment. I have access to this and it does work, but a client with a 400 does not have the licensed program to use STRSQL. The issue is that STRSQL will prompt if this is something I really want to do.
To get at the data I'm using SQuirrel SQL client with the JT400 JDBC driver... So I guess with the system insisting on prompting (and actually no way of getting the prompt even without STRSQL) it won't let me do it.
So I guess I'm stuck doing what I'm doing... creating a new table and copying the data and then swapping the tables.
The only way I found to get jdbc to work is to first manually change the default for this message. Then run your update application. In our case we use Liquibase. I could get the java's CommandCall to call ADDRPYLE and CHGJOB INQMSGRPY(*SYSRPYL), but it never actually allowed the alter table * drop column * to not give the follow error:
Error:
10 -- A cancel reply to an inquiry message was received.
Working Command:
CHGMSGD MSGID(CPA32B2) MSGF(QSYS/QCPFMSG) DFT('I')
Reference:
http://knowledgebase.progress.com/articles/Article/9678
green screen -- STRSQL will give you error msg to answer
alter table devlibsc/trklst drop column "ST"
Change of file TRKLST may cause data to be lost. (C I)
Here’s the scenario:
You load a page, which renders based on the data in the database (call these the “assumptions”)
Someone changes the assumptions
You submit your page
ERROR!
The general pattern to solve this problem is this (right?):
In your save proc, inside a begin and commit transaction, you validate your assumptions first. If any of them changed, you should return a graceful error message, something like an XML list of the ID’s you had problems with, that you handle in the page rather than let it be handled by the default error handling infrastructure.
So my question is what is the best way to do that?
Return the xml list and an error flag in out parameters that are unset and 0 if it completes correctly?
Use an out parameter to return an error status, and the result of the proc be either the error list or the valid results of the proc?
Something else? (I should note that raiseerror would cause the proc to be in error, and get picked up by the default error handling code)
Update: I would like to return a maniplatable list of IDs that failed (I plan to highlight those cells in the application). I could return them in CSV format in RAISEERROR, but that seems dirty.
I agree - I like RAISEERROR:
-- Validate #whatever
IF #whatever >= '5'
BEGIN
RAISERROR ('Invalid value for #whatever - expected a value less than 5, but received %s.', 10, 1, #whatever)
RETURN 50000
END;
Use the RAISERROR function with the appropriate severity and/or wait level. If you use a low severity this does not necessarily cause an exception, as you contend, and with .Net at least its pretty simple to retrieve these messages. The only downside is that with the StoredProcedure command type in .Net messages are only pumped in groups of 50.
Stored procedures can return multiple result sets. Based on your update, you could also insert errored ids into a temporary table, and then at the end of your procedure select the records from that table as an additional result set you can look at.
I would do an output parameter with a message, the return will already have something which is not 0 if there is an error
also be careful with doomed transaction and check with xact_error, see Use XACT_ABORT to roll back non trapable error transactions