Updation in stored procedure
Hi ,
I have a stored procedure in which one part updates a table.If atleast one row is affected then I want to do some processing .How can I get the information after the update statement is fired , that at least one row in the table is affected?
Regards,
Rahul
we can use 'sql%rowcount' to check number of rows processed
Similar Messages
-
Reports in BIDS does not update when stored procedure is modified
Hi,
I am using SQL Server 2008 R2 SP1, and BIDS 2008 SP1. The problem I am about to define does NOT happen when the report is deployed to the report server, but only within the report development environment (BIDS).
From within BIDS my reports are fed by stored procedures. The problem is when I modify a stored procedure in Management Studio, and refresh the report from within BIDS, the report does not reflect the new changes made in the stored procedure. So far I have
found one clumsy solution to this problem:
1) Go to the folder where the project is saved on the file system.
2)Find the ".data" file that is associated to the particular report, then delete it. For instance, if my report name is TestReport.rdl, find the file named TestReport.rdl.data, then delete it.
However, I would like to find a better, and permanent solution. Please comment.
Thank you!Hi AmirBabazadeh,
Base on my research, this issue is caused by data caching in the Business Intelligence Development Studio (BIDS). When we modify the stored procedure in Management Studio, but the data of the report doesn’t change, then it will try to cached data when reprocessing
the report. In this scenario, we should try to refresh the report/dataset, or delete the .rdl.data file to avoid this issue as you are now doing.
In order to refresh the data of the report, the following two methods are for your reference:
Manual refresh: Re-run the stored procedure with Query Designer in Dataset Properties dialog box.
Auto refresh: Set the AutoRefresh property of report to an appropriate value in the Properties window.
Hope this helps.
Thanks,
Katherine Xiong
If you have any feedback on our support, please click
here.
Katherine Xiong
TechNet Community Support -
Error w/ UPDATE in Stored Procedure - ORA-06553 PLS-306
I get the following error when executing my stored proc. from a Perl script:
DBI ERROR: ORA-06553: PLS-306: wrong number or types of arguments in call to 'UPDATE_USER_PROJMGR' (DBD ERROR: OCIStmtExecute),
QUERY: DBI::st=HASH(0x238cd4)Now, it's passing the correct number of values, the UPDATE stmt stores them in the proper order and the procedure when created showed it was done so with no errors.
What value could be out of whack with Oracle here? I don't get it. If anyone sees what I'm doing wrong here, please suggest it.
Thanks!
Here's my stored proc.
CREATE OR REPLACE PROCEDURE UPDATE_USER_PROJMGR
(dp_regleg IN DEFAULT_PROJECT_USER.REG_LEGAL%type,
dp_netcred IN DEFAULT_PROJECT_USER.NETCRED_LOSS%type,
dp_expreduc IN DEFAULT_PROJECT_USER.EXPENSE_REDUC_CKB%type,
dp_stratgoal IN DEFAULT_PROJECT_USER.STRAT_GOALS%type,
dp_audcompl IN DEFAULT_PROJECT_USER.AUDIT_COMPL%type,
dp_revgen IN DEFAULT_PROJECT_USER.REV_GEN%type,
dp_cacs IN DEFAULT_PROJECT_USER.CACS%type,
dp_custit IN DEFAULT_PROJECT_USER.CUSTOMIT%type,
dp_custimpact IN DEFAULT_PROJECT_USER.CUST_IMPACT%type,
dp_callmgt IN DEFAULT_PROJECT_USER.CALL_MGT%type,
dp_calltrk IN DEFAULT_PROJECT_USER.CALL_TRACK%type,
dp_citilink IN DEFAULT_PROJECT_USER.CITILINK%type,
dp_desktop IN DEFAULT_PROJECT_USER.DESKTOP%type,
dp_dialer IN DEFAULT_PROJECT_USER.DIALER%type,
dp_dri IN DEFAULT_PROJECT_USER.DRI%type,
dp_engr IN DEFAULT_PROJECT_USER.ENGINEER%type,
dp_img IN DEFAULT_PROJECT_USER.IMAGING%type,
dp_ipdt IN DEFAULT_PROJECT_USER.IPDT%type,
dp_mainfram IN DEFAULT_PROJECT_USER.MAINFR%type,
dp_miscoth IN DEFAULT_PROJECT_USER.MISC_OTHER%type,
dp_mortserv IN DEFAULT_PROJECT_USER.MORTSERV%type,
dp_mortweb IN DEFAULT_PROJECT_USER.MORTWEB%type,
dp_nonmortserv IN DEFAULT_PROJECT_USER.NON_MORTSERV%type,
dp_origplat IN DEFAULT_PROJECT_USER.ORIG_PLAT%type,
dp_qualmapping IN DEFAULT_PROJECT_USER.QUAL_MAP%type,
dp_datawarehse IN DEFAULT_PROJECT_USER.DATAWARE_REPTS%type,
dp_servappvend IN DEFAULT_PROJECT_USER.SERV_APP_VDR%type,
dp_sbend IN DEFAULT_PROJECT_USER.SOUTHBEND%type,
dp_websvcg IN DEFAULT_PROJECT_USER.WEB_SVCG%type,
dp_projmgr IN DEFAULT_PROJECT_PROJMGR.PROJ_MGR%type,
dp_status IN DEFAULT_PROJECT_PROJMGR.STATUS%type,
dp_projtype IN DEFAULT_PROJECT_PROJMGR.IT_PROJ_TYPE%type,
dp_projnum IN DEFAULT_PROJECT_PROJMGR.IT_PROJNUMBER%type,
defprodid IN NUMBER)
IS BEGIN
-- UPDATE STATEMENT
UPDATE DEFAULT_PROJECT_USER SET
REG_LEGAL = dp_regleg, NETCRED_LOSS = dp_netcred,EXPENSE_REDUC_CKB = dp_expreduc, STRAT_GOALS = dp_stratgoal, AUDIT_COMPL = dp_audcompl,
REV_GEN = dp_revgen,CACS = dp_cacs, CUSTOMIT = dp_custit, CUST_IMPACT = dp_custimpact,CALL_MGT = dp_callmgt,
CALL_TRACK = dp_calltrk,CITILINK = dp_citilink,DESKTOP = dp_desktop,DIALER = dp_dialer,DRI = dp_dri,
ENGINEER = dp_engr,IMAGING = dp_img,IPDT = dp_ipdt,MAINFR = dp_mainfram,MISC_OTHER = dp_miscoth,MORTSERV = dp_mortserv,
MORTWEB = dp_mortweb,NON_MORTSERV = dp_nonmortserv,ORIG_PLAT = dp_origplat,QUAL_MAP = dp_qualmapping,DATAWARE_REPTS = dp_datawarehse,
SERV_APP_VDR = dp_servappvend,SOUTHBEND = dp_sbend,WEB_SVCG = dp_websvcg
WHERE DEFPROJ_ID = defprodid;
UPDATE DEFAULT_PROJECT_PROJMGR SET
PROJ_MGR = dp_projmgr,STATUS = dp_status,IT_PROJ_TYPE = dp_projtype,IT_PROJNUMBER = dp_projnum
WHERE DEFPROJ_ID = defprodid;
COMMIT;
END UPDATE_USER_PROJMGR;
/Here's my Perl script callable stmt:
my $sth2 = $dbh->prepare(q{CALL UPDATE_USER_PROJMGR(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)});
$sth2->execute($reglegal,$netcredloss,$expreduc,$stratgoal,$audcomp,$revgen,$cacs,$custit,$custimp,$callmgt,$calltrkl,$citlink,$deskt,$dialer,$dri,$engineering, $imaging,$ipdt,$mframe,$miscoth,$mortserv,$mortweb,$nonmortserv,$origpltfrm,$qualmap,$dataware,$servapp,$sbdev,$websvcg,$projmgr,$status,$itprojtype,$itprojnum)or do {
print('err', "<img src='../spacer.gif' width='1' height='150'>ERROR: Could not execute SQL! Error: " . $dbh->errstr);
};and the values getting passed:
Holly Spradlin
Withdrawn
PRF
1222
Y
Y
N
N
Y
Y
Y
N
Y
N
N
N
Y
N
N
N
N
N
Y
Y
Y
N
N
N
N
N
N
N
NI get no compile errors or anything until I submit the form to update.
Any help would be appreciated...if I get it solved, I'll reply right away - thanks.try manually executing the procedure to check for the
errors
SQL> execute UPDATE_USER_PROJMGR('Holly
Spradlin','Withdrawn','PRF',1222,'Y','Y','N','N','Y',
Y','Y','N','Y','N','N','N','Y','N','N','N','N','N','Y'
,'Y','Y','N','N','N','N','N','N','N','N');3360 is right you have only supplied 33 parameters
while your procedures requires 34 parameters.ok, did this and did get the error:
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'UPDATE_USER_PROJMGR'
ORA-06550: line 1, column 7:but I wonder why I can't specify the ID value as my sequence's currval - ?
Let me doublecheck my sequence.
OK, I got it!!! thanks, guys, for all your help!!
I just needed to back to the callable statement in the perl script itself and add the last ID param.
Thanks for pointing that out!!
Message was edited by:
user515689 -
SQL Server Service Broker Updating Stored procedure
how can you update the service broker stored procedure. when i update the stored procedure the changes dont come into affect. i have tried to alter the queue, waited for all jobs to finish, but some how still the old stored procedure is running. is there any
way i can force changes to the stored procedure.
i have tried sql profiler tracing but that didnt show any changes.
I cannot alter the service broker stored procedure, when I update the stored procedure it does not show any error and successfully gets updated but the changes does not come into affect.
Is it because I need to stop the queue of the service broker on both databases before the changes could come into affect?
Note: the service broker stored procedures produce and read xmls.Presumably, this is because the procedure is executing when you alter the procedure. And if the procedure never exits, the old code will keep on running. One way to address this is to have the procedure to return if a new message has not been picked up in,
say, 1000 milliseconds.
Here is a repro to shows what I'm talking about.
------------------------------- Service Broker Objects ------------------------------------------
CREATE MESSAGE TYPE OrderRequest VALIDATION = NONE
CREATE MESSAGE TYPE OrderResponse VALIDATION = NONE
go
CREATE CONTRACT OrderContract
(OrderRequest SENT BY INITIATOR,
OrderResponse SENT BY TARGET)
go
CREATE QUEUE OrderRequests WITH STATUS = OFF
CREATE QUEUE OrderResponses WITH STATUS = ON
go
CREATE SERVICE OrderRequests ON QUEUE OrderRequests (OrderContract)
CREATE SERVICE OrderResponses ON QUEUE OrderResponses (OrderContract)
go
-- Procedure to send a message and receive a response.
CREATE PROCEDURE send_and_get_answer AS
DECLARE @handle uniqueidentifier,
@binary varbinary(MAX)
SELECT @binary = CAST (N'Kilroy was here' AS varbinary(MAX))
BEGIN DIALOG CONVERSATION @handle
FROM SERVICE OrderResponses
TO SERVICE 'OrderRequests'
ON CONTRACT OrderContract
WITH ENCRYPTION = OFF
;SEND ON CONVERSATION @handle
MESSAGE TYPE OrderRequest (@binary)
WAITFOR (RECEIVE TOP (1)
@handle = conversation_handle,
@binary = message_body
FROM OrderResponses)
SELECT cast(@binary AS nvarchar(MAX)) AS response
END CONVERSATION @handle
go
-- Procedure to process a message
CREATE PROCEDURE ProcessOrders AS
SET NOCOUNT, XACT_ABORT ON
DECLARE @DialogHandle uniqueidentifier,
@MessageType sysname,
@binarydata varbinary(MAX)
-- Get next message of the queue.
WAITFOR (
RECEIVE TOP (1) @DialogHandle = conversation_handle,
@MessageType = message_type_name,
@binarydata = message_body
FROM OrderRequests
SELECT @binarydata = CAST( reverse( CAST( @binarydata AS nvarchar(MAX) )) AS varbinary(MAX))
; SEND ON CONVERSATION @DialogHandle
MESSAGE TYPE OrderResponse (@binarydata)
END CONVERSATION @DialogHandle
go
-- Make this an activaton procedure.
ALTER QUEUE OrderRequests WITH
STATUS = ON,
ACTIVATION (STATUS = ON,
PROCEDURE_NAME = ProcessOrders,
MAX_QUEUE_READERS = 1,
EXECUTE AS OWNER)
go
-------------------------------- Send a message -------------------------------------------
EXEC send_and_get_answer
go
------------------------ Change the procedure --------------------------------
ALTER PROCEDURE ProcessOrders AS
SET NOCOUNT, XACT_ABORT ON
DECLARE @DialogHandle uniqueidentifier,
@MessageType sysname,
@binarydata varbinary(MAX)
-- Get next message of the queue.
WAITFOR (
RECEIVE TOP (1) @DialogHandle = conversation_handle,
@MessageType = message_type_name,
@binarydata = message_body
FROM OrderRequests
SELECT @binarydata = CAST( upper( CAST( @binarydata AS nvarchar(MAX) )) AS varbinary(MAX))
; SEND ON CONVERSATION @DialogHandle
MESSAGE TYPE OrderResponse (@binarydata)
END CONVERSATION @DialogHandle
go
-------------------------------- Send new message -------------------------------------------
EXEC send_and_get_answer -- Still produces a message in reverse.
EXEC send_and_get_answer -- Now we get the expected result.
go
DROP SERVICE OrderRequests
DROP SERVICE OrderResponses
DROP QUEUE OrderRequests
DROP QUEUE OrderResponses
DROP PROCEDURE ProcessOrders
DROP PROCEDURE send_and_get_answer
DROP CONTRACT OrderContract
DROP MESSAGE TYPE OrderRequest
DROP MESSAGE TYPE OrderResponse
go
Erland Sommarskog, SQL Server MVP, [email protected] -
Returned fields are not showing up under stored procedure
First I would like to say I haven't used crystal reports before.
I created a crystal report in VS2008 and under Database fields I pointed to my stored procedure. The parameter fields show up but there are no return fields under the stored procedure. I tested the SP in SQL Management Studio and it works correctly and returns the correct fields. When selecting the SP I tried unselecting "Set to Null Value" for each of the parameters and entered values I knew would return fields and the fields show up under the SP but they are filled with the data from the parameters I used. Which I would expect. If I go back to using null, the fields disappear.
I also had this problem when I updated another Report after adding a new field to be returned from a SP. I fiddled around with it and got it working but not sure how or why it saw the fields when I got it working.
And today I updated a stored procedure to use a string parameter and not an integer parameter. After I updated the SP in VS2008 using the field explorer, the return fields disappear. What am I doing wrong?Hi Don,
Thanks for the reply. I verified the database multiple times before posting and just verified it again. No luck. Also the SP has only one select.
I found some crystal report cds with 8.5 (the newest I could find), I installed it and tried to use the SP and it gave me the following error:
"There are no return fields in the file". VS2008 does not give this error.
I tried using crystal reports with all the SPs I altered and I get the same error. Most of the changes to the SPs are in the where cause (Changing from field = @field to field IN (@fields) and changing a parameter from an int to a string. Also as a side note, when setting up the data source I am choosing to use nulls. Is this correct? The SPs were all written using SQL string format if that makes any difference.
UPDATE: I tried using discree values that I knew would return values and the return fields show up. They are populated with the expected values but if I use these values all my reports will be the same. As I would expect. So why doesn't it work for NULL values? Maybe my thinking is wrong here but isn't null values used so you can dynamically select values for the parameters at runtime?
Edited by: Kenshinofkin on May 12, 2011 7:01 PM -
I've just tried to "Submit Feedback" but the page just gives me an error which means nothing to anyone which says "You are not authorized to submit the feedback for this connection.". Why am I not authorised how do I become authorised etc
etc. Anyway :-)
I've trying to report that the stored procedure in Sql Server Replication in 12.0.2000 has an issue with data type lengths. This procedure sp_MSdetect_nonlogged_shutdown uses data lengths of nvarchar(2048) but the MSDB sysjobhistory table has a message field
length of 4000. Which causes the above stored procedure to crash.
Best Regards
RichardThis is the work around
1. Stop SQL Server service.
2. On command prompt run the following command to run the server in single user mode – be sure to replace the MSSQLSERVER with the actual instance name
C:\>”C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe” -sMSSQLSERVER -m
3. Connect to SQL server with SSMS as the server administrator
4. Run the following to change the database to the system resource database: “USE mssqlsystemresource”
5. Run the following to update the stored procedure (only change is to make NVARCHAR(4000))
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER procedure [sys].[sp_MSdetect_nonlogged_shutdown]
@subsystem nvarchar(60),
@agent_id int
as
begin
declare @job_id binary(16)
declare @agent_name sysname
declare @message nvarchar(4000)
declare @retcode int
declare @runstatus int
declare @run_date int
declare @run_time int
declare @run_date_orig int
declare @run_time_orig int
declare @merge_session_id int
-- security check
-- only db_owner can execute this
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end
-- Detect if the agent was shutdown without a logged reason
if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'SNAPSHOT'
begin
if exists (select runstatus from MSsnapshot_history where
agent_id = @agent_id and
runstatus <> 2 and
--CAC runstatus <> 5 and
runstatus <> 6 and
timestamp = (select max(timestamp) from MSsnapshot_history where agent_id = @agent_id))
begin
select @job_id = job_id, @agent_name = name from MSsnapshot_agents where id = @agent_id
end
end
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'LOGREADER'
begin
if exists (select runstatus from MSlogreader_history where
agent_id = @agent_id and
runstatus <> 2 and
--CAC runstatus <> 5 and
runstatus <> 6 and
timestamp = (select max(timestamp) from MSlogreader_history where agent_id = @agent_id))
begin
select @job_id = job_id, @agent_name = name from MSlogreader_agents where id = @agent_id
end
end
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'DISTRIBUTION'
begin
if exists (select runstatus from MSdistribution_history where
agent_id = @agent_id and
runstatus <> 2 and
--CAC runstatus <> 5 and
runstatus <> 6 and
timestamp = (select max(timestamp) from MSdistribution_history where agent_id = @agent_id))
begin
select @job_id = job_id, @agent_name = name from MSdistribution_agents where id = @agent_id
end
end
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'MERGE'
begin
if exists (select runstatus from dbo.MSmerge_sessions where
agent_id = @agent_id and
runstatus <> 2 and
--CAC runstatus <> 5 and
runstatus <> 6 and
session_id = (select top 1 session_id from dbo.MSmerge_sessions where agent_id = @agent_id order by session_id desc))
begin
select @job_id = job_id, @agent_name = name from dbo.MSmerge_agents where id = @agent_id
select top 1 @merge_session_id = session_id from dbo.MSmerge_sessions
where agent_id = @agent_id
order by session_id desc
end
end
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'QUEUEREADER'
begin
if exists (select runstatus from MSqreader_history where
agent_id = @agent_id and
runstatus <> 2 and
--CAC runstatus <> 5 and
runstatus <> 6 and
timestamp = (select max(timestamp) from MSqreader_history where agent_id = @agent_id))
begin
select @job_id = job_id, @agent_name = name from MSqreader_agents where id = @agent_id
end
end
-- If no job_id assume shutdown was logged properly
if @job_id is null
return 0
-- Get last message from SQL Agent History table
create table #JobHistory (
instance_id int NOT NULL,
job_id uniqueidentifier NOT NULL,
job_name sysname NOT NULL,
step_id int NOT NULL,
step_name nvarchar(100) NOT NULL,
sql_message_id int NOT NULL,
sql_severity int NOT NULL,
message nvarchar(4000) NOT NULL,
run_status int NOT NULL,
run_date int NOT NULL,
run_time int NOT NULL,
run_duration int NOT NULL,
operator_emailed sysname NULL,
operator_netsent sysname NULL,
operator_paged sysname NULL,
retries_attempted int NOT NULL,
server sysname NOT NULL
if @@error <> 0
return 1
-- Insert last history for step_id 2 (Agent running)
insert TOP(2) into #JobHistory exec sys.sp_MSreplhelp_jobhistory @job_id = @job_id, @step_id = 2,
@mode = 'FULL'
declare cursorHistory cursor local fast_forward for
select message,
run_status,
run_date,
run_time
from #JobHistory
order by run_date desc,
run_time desc,
instance_id asc
open cursorHistory
fetch cursorHistory into @message, @runstatus, @run_date, @run_time
select @run_date_orig = @run_date,
@run_time_orig = @run_time
while @@fetch_status <> -1
begin
-- as long as we are looking at the history for the same run
-- date and time then we should log all rows. there should
-- be 2 rows since we perform a TOP on exec sp_help_jobhistory
if @run_date_orig = @run_date
and @run_time_orig = @run_time
begin
-- Map SQL Agent runstatus to Replication runstatus
set @runstatus =
case @runstatus
when 0 then 6 -- Fail mapping
when 1 then 2 -- Success mapping
when 2 then 5 -- Retry mapping
when 3 then 2 -- Shutdown mapping
when 4 then 3 -- Inprogress mapping
when 5 then 0 -- Unknown is mapped to never run
end
-- If no message, provide a default message
-- Also overwrite all inprogress messages to be "See SQL Agent history log".
-- This is to prevent "Agent running. See monitor" to be logged into repl monitor.
-- In this case (the last job history message is InProgress), we know that
-- there have been failures of SQL Server Agent history logging.
-- In fact, the only possible "in progress" msg in SQL Agent job step
-- history for push jobs is "Agent running. See monitor". It is confusing that those
-- messages showed up in repl monitor.
if @message is null or @runstatus = 3
begin
raiserror(20557, 10, -1, @agent_name)
select @message = formatmessage(20557, @agent_name)
end
if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'SNAPSHOT'
exec @retcode = sys.sp_MSadd_snapshot_history @agent_id = @agent_id, @runstatus = @runstatus,
@comments = @message
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'LOGREADER'
exec @retcode = sys.sp_MSadd_logreader_history @agent_id = @agent_id, @runstatus = @runstatus,
@comments = @message
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'DISTRIBUTION'
exec @retcode = sys.sp_MSadd_distribution_history @agent_id = @agent_id, @runstatus = @runstatus,
@comments = @message
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'MERGE'
exec @retcode = sys.sp_MSadd_merge_history @agent_id = @agent_id, @runstatus = @runstatus,
@comments = @message, @called_by_nonlogged_shutdown_detection_agent = 1, @session_id_override = @merge_session_id
else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'QUEUEREADER'
exec @retcode = sys.sp_MSadd_qreader_history @agent_id = @agent_id, @runstatus = @runstatus,
@comments = @message
if @@error <> 0 or @retcode <> 0
return 1
end
fetch cursorHistory into @message, @runstatus, @run_date, @run_time
end
close cursorHistory
deallocate cursorHistory
drop table #JobHistory
end
6. Return the system resource database to read-only – “alter database mssqlsystemresource set read_only”
7. Shutdown the instance – “shutdown”
8. Start the instance using the service as usual -
Help with Command - Stored Procedure
Hi all,
I'm having a great deal of difficulty getting my head around
an update command / stored procedure, I've pulled out all of my
books and spent the last two days on Google which has made my
confusion worse. In simple terms what I'm trying to do is update a
field in a table with the value y, but based on certain criteria.
So my table has the following fields -
JBAID
JBASiteID
JBADatePosted
JBAPostFor
JBANotified
What i want to do is update the value of field JBANotified on
all records that meeting the following criteria to Y
The criteria is -
WHERE DATEADD(d,JBAPostFor,JBADatePosted) BETWEEN DATEADD(d,
-7, GETDATE()) AND GETDATE() AND JBANotified = 'n' AND JBASiteID =
MMColParam (where MMColParam is Session("SITEID"))
So I've just tried building a command / stored procedure -
which reads (see attached code)(more than likely all wrong)
The things that I cant get my head around are -
Firstly getting the code right in the first place, running
the command on page load and then when the command has run
redirecting to the next page.
I really would appreciate some help with this -
thanks allEd Stewart wrote:
> Are you using CS3 with ASP/VBScript? There is a bug in
the command
> implementation that has this function broken.
>
> I asked about it in this forum several months ago, but
now I can't find my
> original post, but I did find another post that talks
about the same thing:
>
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=12&catid=26
> 3&threadid=1281539&enterthread=y
>
> My solution is to drop back to DW8 for command editing,
but use CS3 for
> everything else. I don't know what you're supposed to do
if you don't have an
> earlier version.
>
> It looks like your sql is correct, but the bug prevents
the second code block
> is not being updated with the correct values.
>
> I hope a solution is forthcoming....
>
Create a stored procedure and then use a recordset to
exectute it,
making sure the recordset has matching parameters that the
stored
procedure expects.
Commands are broken, I reported it to Adobe and they said it
might get
fixed in the next version.
Steve -
Deleting a stored procedure from an EF 6.1 Database First C# solution
I added a stored procedure to a EF 6.1.x Database First solution. Then I changed the stored procedure on SQL Server. Hoped that the changes would be updated in EF when I used Update Model from Database from the Designer. But they weren't. Tables update correctly
when I change the table's schema within SQL Server. Function Imports and classes generated from a stored procedure don't seem to update if I update the stored procedure however.
So I figured that I would delete the stored procedure from the model and then re-add it. But wait! I couldn't find a way to delete the stored procedure from the model! There's no object to delete from the design surface when the object is a stored procedure!.
First I tried deleting the class from the Solution Explorer. Bad idea. An update from the design surface duplicated the class!.
The only way I found that you could completely remove a stored procedure from a Database First EF solution is to open the model browser and delete any class reference from the model's ComplexTypes , FunctionImports and from model.Store's StoredProcedures.
Seems like a lot of work.
Isn't there an easier way? Is it this hard in Code First?
MichaelHello,
>>Isn't there an easier way? Is it this hard in Code First?
Curently, it seems that there is not a easy enough to delete a store produce in database first approach.You could post a feedback about this issue to:
http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions
When using stote produce with code first approach, it is easy since we do not need to import these SPs to the model, for details, you could check this link:
https://entityframework.codeplex.com/wikipage?title=Code%20First%20Insert/Update/Delete%20Stored%20Procedure%20Mapping
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to get an updatable ADODB Recordset from a Stored Procedure?
In VB6 I have this code to get a disconnected ADODB Recordset from a Oracle 9i database (the Oracle Client is 10g):
Dim conSQL As ADODB.Connection
Dim comSQL As ADODB.Command
Dim recSQL As ADODB.Recordset
Set conSQL = New ADODB.Connection
With conSQL
.ConnectionString = "Provider=OraOLEDB.Oracle;Password=<pwd>;Persist Security Info=True;User ID=<uid>;Data Source=<dsn>"
.CursorLocation = adUseClientBatch
.Open
End With
Set comSQL = New ADODB.Command
With comSQL
.ActiveConnection = conSQL
.CommandType = adCmdStoredProc
.CommandText = "P_PARAM.GETALLPARAM"
.Properties("PLSQLRSet").Value = True
End With
Set recSQL = New ADODB.Recordset
With recSQL
Set .Source = comSQL
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open
.ActiveConnection = Nothing
End With
The PL/SQL Procedure is returning a REF CURSOR like this:
PROCEDURE GetAllParam(op_PARAMRecCur IN OUT P_PARAM.PARAMRecCur)
IS
BEGIN
OPEN op_PARAMRecCur FOR
SELECT *
FROM PARAM
ORDER BY ANNPARAM DESC;
END GetAllParam;
When I try to update some values in the ADODB Recordset (still disconnected), I get the following error:
Err.Description: Multiple-step operation generated errors. Check each status value.
Err.Number: -2147217887 (80040E21)
Err.Source: Microsoft Cursor Engine
The following properties on the Command object doesn't change anything:
.Properties("IRowsetChange") = True
.Properties("Updatability") = 7
How can I get an updatable ADODB Recordset from a Stored Procedure?4 years later...
I was having then same problem.
Finally, I've found how to "touch" the requierd bits.
Obviously, it's hardcore, but since some stupid at microsoft cannot understand the use of a disconnected recordset in the real world, there is no other choice.
Reference: http://download.microsoft.com/downlo...MS-ADTG%5D.pdf
http://msdn.microsoft.com/en-us/library/cc221950.aspx
http://www.xtremevbtalk.com/showthread.php?t=165799
Solution (VB6):
<pre>
Dim Rst As Recordset
Rst.Open "select 1 as C1, '5CHARS' as C5, sysdate as C6, NVL(null,15) as C7, null as C8 from DUAL", yourconnection, adOpenKeyset, adLockBatchOptimistic
Set Rst.ActiveConnection = Nothing
Dim S As New ADODB.Stream
Rst.Save S, adPersistADTG
Rst.Close
Set Rst = Nothing
With S
'Debug.Print .Size
Dim Bytes() As Byte
Dim WordVal As Integer
Dim LongVal As Long
Bytes = .Read(2)
If Bytes(0) <> 1 Then Err.Raise 5, , "ADTG byte 0, se esperaba: 1 (header)"
.Position = 2 + Bytes(1)
Bytes = .Read(3)
If Bytes(0) <> 2 Then Err.Raise 5, , "ADTG byte 9, se esperaba: 2 (handler)"
LongVal = Bytes(1) + Bytes(2) * 256 ' handler size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 3 Then Err.Raise 5, , "ADTG, se esperaba: 3 (result descriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' result descriptor size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 16 Then Err.Raise 5, , "ADTG, se esperaba: 16 (adtgRecordSetContext)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 5 Then Err.Raise 5, , "ADTG, se esperaba: 5 (adtgTableDescriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(1)
If Bytes(0) <> 6 Then Err.Raise 5, , "ADTG, se esperaba: 6 (adtgTokenColumnDescriptor)"
Do ' For each Field
Bytes = .Read(2)
LongVal = Bytes(0) + Bytes(1) * 256 ' token size
Dim NextTokenPos As Long
NextTokenPos = .Position + LongVal
Dim PresenceMap As Long
Bytes = .Read(3)
PresenceMap = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(2)), 2))
Bytes = .Read(2) 'ColumnOrdinal
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
'Aca pueden venir: friendly_columnname, basetable_ordinal,basetab_column_ordinal,basetab_colname
If PresenceMap And &H800000 Then 'friendly_columnname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
If PresenceMap And &H400000 Then 'basetable_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H200000 Then 'basetab_column_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H100000 Then 'basetab_colname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
Bytes = .Read(2) 'adtgColumnDBType
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
Bytes = .Read(4) 'adtgColumnMaxLength
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Precision
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Scale
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Dim ColumnFlags() As Byte, NewFlag0 As Byte
ColumnFlags = .Read(1) 'DBCOLUMNFLAGS, First Byte only (DBCOLUMNFLAGS=4 bytes total)
NewFlag0 = ColumnFlags(0)
If (NewFlag0 And &H4) = 0 Then 'DBCOLUMNFLAGS_WRITE (bit 2) esta OFF
'Lo pongo en ON, ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 Or &H4)
End If
If (NewFlag0 And &H8) <> 0 Then 'DBCOLUMNFLAGS_WRITEUNKNOWN (bit 3) esta ON
'Lo pongo en OFF, ya que no me importa si NO sabes si se puede updatear no, yo lo se, no te preocupes
'ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 And Not &H8)
End If
If (NewFlag0 And &H20) <> 0 Then 'DBCOLUMNFLAGS_ISNULLABLE (bit 5) esta OFF
'Lo pongo en ON, ya que siendo un RST DESCONECTADO, si le quiero poner NULL, le pongo y listo
NewFlag0 = (NewFlag0 Or &H20)
End If
If NewFlag0 <> ColumnFlags(0) Then
ColumnFlags(0) = NewFlag0
.Position = .Position - 1
.Write ColumnFlags
End If
.Position = NextTokenPos
Bytes = .Read(1)
Loop While Bytes(0) = 6
'Reconstruyo el Rst desde el stream
S.Position = 0
Set Rst = New Recordset
Rst.Open S
End With
'TEST IT
On Error Resume Next
Rst!C1 = 15
Rst!C5 = "MUCHOS CHARS"
Rst!C7 = 23423
If Err.Number = 0 Then
MsgBox "OK"
Else
MsgBox Err.Description
End If
</pre> -
Calling a stored procedure before row update without using triggers
I have got two tables Main Table(Table1) and History Table(Table2), whenever an update is done on Table1 i want to insert the old row before update to Table2, so that i have history available for that record.
My doubt is
how to refer to old value (values b4 update) in a stored procedure?
how to call a stored procedure b4 every row update(on the database side as we do with tiggers)?
I want to write a stored procedure where in i will insert the old row values ( value b4 update ) to Table2.
Any Help would be great....sample code calling procedure before insert:
DriverManager.registerDriver(new someDriver);
Connection conn = DriverManager.getConnection(driver,uname,pword);
CallableStatement cs = conn.prepareCall("{call procedureName(?,?)}");
cs.setString(1,userName);
cs.registerOutParameter(2,Types.VARCHAR);
cs.execute();
success = cs.getString(2);
PreparedStatement pstmt = conn.prepareStatement("insert into sometable values(?,?)");
pstmt.setString(1,userName);
pstmt.setString(2,password);
pstmt.executeUpdate();
conn.commit();
cs.close();
conn.close(); -
Incorrect Update Count by executing a stored procedure from Java
Hi Guys,
I am calling a stored procedure from the java program which is modifying the rows of a table. Now I want to know how many rows have been modified by executing the stored procedure. I am writing the following code for the purpose:
OracleCallableStatement stmt =
(oracle.jdbc.driver.OracleCallableStatement)con.prepareCall("{callsp_um_setForumID(?,?)}");
stmt.setInt(1,101);
stmt.setInt(2,666);
n = stmt.executeUpdate();
System.out.println(n + " row(s) updated");
This procedure is actually modifying the table(When I query the databse it has modified 1 row). But it is returning a value 0 and is printing "0 row(s) updated".
Is there a way by which I can find out the number of rows updated by executing the stored procedure?
Thanks
Sachin
[email protected]I'm no expert on this, but I have a similar call where I fetch
an Oracle REF CURSOR from a call to a stored function. If you
fetch the cursor as an Object from your CallableStatement, you
can then cast it to a ResultSet e.g.
mystatement.executeUpdate();
ResultSet rs = (ResultSet) mystatement.getObject(1);
Then you should be able to loop through your ResultSet as usual.
Good luck!
Chris -
How to get an UPDATABLE REF CURSOR from the STORED PROCEDURE
using C# with
ORACLE OLE DB version: 9.0.0.1
ADO version: 2.7
I returns a REF CURSOR from a stored procedure seems like:
type TCursor is ref cursor;
procedure test_out_cursor(p_Dummy in varchar, p_Cur out TCursor) is
begin
open p_Cur for select * from DUAL;
end;
I create an ADO Command object and set
cmd.Properties["IRowsetChange"].Value = true;
cmd.Properties["Updatability"].Value = 7;
cmd.Properties["PLSQLRSet"].Value = 1;
cmd.CommandText = "{CALL OXSYS.TEST.TEST_OUT_CURSOR(?)}";
and I use a Recordset object to open it:
rs.Open(cmd, Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockBatchOptimistic,
(int) ADODB.CommandTypeEnum.adCmdText +
(int) ADODB.ExecuteOptionEnum.adOptionUnspecified);
The rs can be opened but can NOT be updated!
I saved the recordset into a XML file and there's no
rs:baseschema/rs:basetable/rs:basecolumn
attributes for "s:AttributeType" element.
Any one have idea about this?
thanks very muchIt is not possible through ADO/OLEDB.
Try ODP.NET currently in Beta, it is possible to update DataSet created with refcursors. You need to specify your custom SQL or SP to send update/insert/delete.
As I remember there is a sample with ODP.NET Beta 1 just doing this. -
With clause in a stored procedure with update
create table TEMP_STAGE as
(select '111111' student_id, 'N' TMP_TEST FROM DUAL
UNION
select '111111' student_id, 'N' TMP_TEST FROM DUAL
UNION
select '222222' student_id, 'N' TMP_TEST FROM DUAL
CREATE OR REPLACE PROCEDURE TEMP_SEC_TEST
AS
BEGIN
UPDATE TEMP_STAGE S
SET S.TMP_TEST = 'Y'
WHERE STUDENT_ID IN
WITH MARK AS
SELECT '111111' STUDENT_ID FROM DUAL
select STUDENT_ID from MARK
END;
I have a huge sql statement with several 'with' tables in the statement...It works if I execute it as a script but it does not work when I put it in a stored procedure.
When I execute the above it gives me an error...
Error Syntax Check (8:9)
Found 'MARK' expecting .....
It gives me an error at the wth Mark as line....
I have to do it in the stored procedure as the statement is very complicated...
Please help.What tool are you using to create the procedure? Error Syntax Check (8:9) is not an Oracle error, nor as far as I know from any Oracle product.
It works just fine in sqlplus.
SQL> CREATE procedure my_p AS
2 BEGIN
3 UPDATE t
4 SET descr = 'Un'
5 WHERE id IN (WITH tmp AS (
6 SELECT 1 x FROM dual)
7 SELECT x FROM tmp);
8 END;
9 /
Procedure created.
SQL> SELECT * FROM t;
ID DESCR
1 One
SQL> exec my_p;
PL/SQL procedure successfully completed.
SQL> SELECT * FROM t;
ID DESCR
1 UnJohn -
Stored Procedure for updating dynamic columns in a table
I have a table with a lot of columns around 30ish
Now I want to create a stored procedure that will update a specific column to a new value.
I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.
here's my Stored Procedure
USE [db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_UpdateData]
@itemID int,
@ColumnName varchar(50),
@newValue nvarchar(50)
AS
BEGIN
Update dbo.ProjectAllocation
Set @ColumnName = @newValue
Where itemID = @itemID END
When I pass the following
@ColumnName: UserName
@newValue: NewUserName
@itemID: 1
it doesnt update row with itemID = 1.
How can I do this?
----------------------- Sharepoint NewbieDid you try my last post method. Its better to use parameterized approach.
Anyway, if you want to change your code,you may need to change as below.....
SET @sql = 'UPDATE dbo.table SET ' + @ColumnName + '=''' + @newValue + ''' WHERE [itemID] = ' + cast(@itemID as varchar(50)); -
How to use the Stored Procedure to update my UDF
I want to use the Stored Procedure to update my UDF U_InstokCS when the warehouse "OnHand" was changed. The UDF is display the stock by cases. I copied the query as follewing. I couldn't see any thing in the UDF after I made some transactions. Can anybody tell me why? How to continue it?
if @transaction_type in ('A','U','D') and @Object_type='64'
begin
Update OITW
Set U_InstokCS = OnHand/(Select T0.NumInBuy from [DBO].[OITM] T0
Where T0.ItemCode = @list_of_cols_val_tab_del)
Where ItemCode = @list_of_cols_val_tab_del
end
Thanks.
Ying ZhangYing,
The use of any stored procedures against the SAP Business One database is not allowed per SAP Support. There is not an instance where you can use SP's. The ONLY SP that you are allowed to use is the SBO_SP_TransactionNotification SP that comes with SAP Business One itself. You can read about the use of this SP from this article...
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e991e2b9-0901-0010-0395-ef5268b00aaf
Eddy
Maybe you are looking for
-
How do I re-enable showing the download files history in the download manager window?
System: Windows XP I am trying to re-enable showing/retaining the list of downloaded files in the download manager window. I want to be able to drag and drop directly from that window into a folder of my choosing. (I used to be able to do this, but a
-
Can I have a second, external HD with a higher OS than my main drive?
I've started to come across a few programs that need OS X 10.4 or higher to run. I have a beautifully stable system with 10.2.8, and I hate to mess that up, especially since my internal CD drive has stopped running, and am using an external CD/DVD dr
-
Using a MIDlet I created a database called "Customers-VM00", with creator ID "VM00", this database has two records: 1) 48476472\Luis\Bello Ortega\201398400000\ 2) 00000000\Jana\Hajkova\144288000000\ Ok, my goal is to get those two lines in my Conduit
-
This is my code : package RENSPackage; import java.io.File; import oracle.toplink.threetier.Server; import oracle.toplink.tools.sessionconfiguration.XMLLoader; import oracle.toplink.tools.sessionmanagement.SessionManager; public class Loader protecte
-
How to restore particular pictures in iphoto backed up via time machine
cant we open an app like iphoto via time machine for a particular date ?? like i want a pic that i deleted from iphoto , how can i do that without restoring full iphoto library???