Store Proc
Hi folks, I’m slowly building up my SP, I don’t fully understand the syntax yet.
I’m trying to retrieve the Customer primary key that has been created for the new customer record, and then assign it to the @CustomerFK parameter, could you give me any pointers on this!
ALTER PROCEDURE [dbo].[AddCustomerDetails]
/***********************Declare variables ***********************/
/******tblCustomer******/
@CustomerID uniqueidentifier,
@Forename nvarchar(50),
@Surname nvarchar(50)
/******tblOrder******/
@OrderID uniqueidentifier,
@CustomerFK nvarchar(50),
@DateOrdered date,
@TimeOrdered time,
@AnyAdditionalInfo nvarchar(Max),
As
Begin TRANSACTION
SET NOCOUNT ON
INSERT INTO [TyreSannerSQL].[dbo].[Customers]
(Forename,
Surname)
OUTPUT INSERTED.CustomerID INTO @CustomerFK
VALUES
(@Forename,
@Surname)
INSERT INTO [TyreSannerSQL].[dbo].[Order]
(OrderID,
CustomerFK,
DateOrdered,
TimeOrdered,
AnyAdditionalInfo)
VALUES
(@OrderID,
@CustomerFK,
@DateOrdered,
@TimeOrdered,
@AnyAdditionalInfo)
COMMIT TRANSACTION
Hi folks, store proc is not working correctly,
@OrderID uniqueidentifier and @OrderID, keep coming up with under line red
SET @CustomerFK = SCOPE_IDENTITY()
USE [TyreSannerSQL]
GO
/****** Object: StoredProcedure [dbo].[AddCustomerDetails] Script Date: 10/06/2014 20:49:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddCustomerDetails]
/******tblCustomer******/
@CustomerID uniqueidentifier,
@Forename nvarchar(50),
@Surname nvarchar(50)
As
Begin TRANSACTION
SET NOCOUNT ON
INSERT INTO [TyreSannerSQL].[dbo].[Customer]
(Forename,
Surname)
VALUES
(@Forename,
@Surname)
SET @CustomerFK = SCOPE_IDENTITY()
/******tblOrder******/
@OrderID uniqueidentifier,
@CustomerFK uniqueidentifier,
@DateOrdered date,
@TimeOrdered time,
@AnyAdditionalInfo nvarchar(Max),
INSERT INTO [TyreSannerSQL].[dbo].[Order]
(OrderID,
CustomerFK,
DateOrdered,
TimeOrdered,
AnyAdditionalInfo)
VALUES
@OrderID,
@CustomerFK,
@DateOrdered,
@TimeOrdered,
@AnyAdditionalInfo
COMMIT TRANSACTIONA
Similar Messages
-
DropDown List Problem for Dynamic Store Proc Parameter in SAP B1 8.8
I am working with the crystal report 2008 in SAP B1 8.8 and the report is used the Store Proc for retrieving data. As i need to show a list of Documnet No (DOCNUM) from Sales Order (ORDR) and Purchase Order (OPOR) for the users to select, i use the Dynamic Parameter as for the Store Proc parameter (@Contno), However, the drop down list can be shown fine in Crystal Report, but cant be shown in "Report Selection Criteria" while opening the Crystal Report through SAP B1.
Therefore, can anyone tell me how to add the dynamic drop down list (cause the documnet no list will be changed very frequently) in the SAP B1 8.8 "Report Selection Criteria" screen.
Thanks!!Classic Crystal Reports and Classic SAP connectivity questions
Classic Crystal Reports and Classic SAP connectivity questions -
To convert the "IBM DB2 Store Procs written in C" to Oracle PL-SQL
Hi, Is it possible to convert the "IBM DB2 Store Procs written in C" to Oracle PL-SQL. If you have any info, PL do let me know. Thanks in advance.
EG :
/* SMG Stored Procedures */
/* DB2 Stored Procedure: OrganisationExists */
/* Linkage: SIMPLE (no NULLs permitted) */
/* Load module name: SMGEC00 */
/* Purpose: DELETE FROM SSE_LOOKUP_MAP */
/* to run. */
/* Parameters: argvÃ1¨ short - return error code - OUT */
/* argvÃ2¨ char - return error message - OUT */
/* argvÃ3¨ char - BLEID - IN */
/* Reason for edit Date Who */
/* Initial version 09/04/03 Arockia */
#pragma runopts(plist(os))
#include <stdlib.h>
#include <string.h>
void main (int argc, char *argvè)
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char bleid??(12??);
EXEC SQL END DECLARE SECTION;
/* Set defaults for error code (argvÃ1¨) and error message (argvÃ2¨) */
strcpy(argv??(2??)," ");
*(int *)argv??(1??) = 0;
strcpy(bleid,argv??(3??));
EXEC SQL
DELETE FROM SSE_LOOKUP_MAP
WHERE BLEID = :bleid;
/* Set error code to record status of last SQL command */
*(int *)argv??(1??) = SQLCODE;
return;For this program, you could do some thing like:
SQL> CREATE TABLE sse_lookup_map(BLEID varchar2(10));
Table created.
SQL> CREATE or replace PROCEDURE test(p_bleid_in IN varchar2)
2 AS
3 BEGIN
4 DELETE FROM sse_lookup_map
5 WHERE BLEID = p_bleid_in;
6 END;
7 /
Procedure created.
SQL> ed
Wrote file afiedt.buf
1* INSERT INTO sse_lookup_map values('test1')
SQL> /
1 row created.
SQL> ed
Wrote file afiedt.buf
1* INSERT INTO sse_lookup_map values('test2')
SQL> /
1 row created.
SQL> SELECT * FROM sse_lookup_map;
BLEID
test1
test2
2 rows selected.
SQL> EXEC test('test1')
PL/SQL procedure successfully completed.
SQL> SELECT * FROM sse_lookup_map;
BLEID
test2
1 row selected.
SQL> -
Getting an error from calling a store proc
this is my code calling a store proc. i got all oracle 8i
drivers imported.
package FMISBean;
import java.sql.*;
import oracle.jdbc.driver.*;
public class getrecordj
public static void main(String [] args){
//global variables
Connection conOrcl=null;
String ProjectID ="222700-";
CallableStatement C_TPRO_J=null;
ResultSet R_TPRO_J = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conOrcl=DriverManager.getConnection("jdbc:odbc:FMISORCL","FMIS_USER","FMIS123");
try{
String SQL ="{ ? = call getJrecord(?) }";
C_TPRO_J = conOrcl.prepareCall(SQL);
//assign the ? to the argument passed
C_TPRO_J.registerOutParameter(1,OracleTypes.CURSOR);
C_TPRO_J.setString(2,ProjectID);
//execute the query
C_TPRO_J.executeQuery();
R_TPRO_J = (ResultSet) C_TPRO_J.getObject(1);
//looping through the resultSet
while (R_TPRO_J.next()){
//create an instance of the class
// JavaBeans JItems = new JavaBeans();
// set it to the Bean
System.out.println(R_TPRO_J.getString(1));
System.out.println(R_TPRO_J.getString(2));
System.out.println(R_TPRO_J.getString(3));
System.out.println(R_TPRO_J.getString(4));
System.out.println(R_TPRO_J.getString(5));
System.out.println(R_TPRO_J.getString(6));
//JItems.setexistingLane(R_TPRO_J.getInt(3));
// JItems.setproposed_lane(R_TPRO_J.getInt(4));
// JItems.setcomnt(R_TPRO_J.getString(5));
// JItems.setcomntType(R_TPRO_J.getString(6));
//add the object to the vector
// V_itemsJ.addElement(JItems);
}catch(SQLException w){
System.out.println(w.getMessage());
}}catch(Exception S){
//returning the vector
// return V_itemsJ;
//closing bracets
the store proc works fine if i test it in sql plus but when i call it from the page i get a dos window error
[oracle][orant]:line 1, colunm 13
PLS: expression is of wrong type
line 1 , colunm 7
PL/SQL: statement ignored
any ideas please would help?Here are some examples to reference:
http://www.javaalmanac.com/egs/java.sql/CallFunction.html
http://www.javaalmanac.com/egs/java.sql/CallProcedure.html
DesQuite -
Pass parameters to sql store proc?
Is it possible to pass parameters from Crystal Report to sql store proc? I know it will prompt for paramters if the report is built based on a parameterized store proc. I am NOT talking about these parameters. I still want user to be able to select parameter values from dropdowns and use them as the procedure parameters.
Reason for my question is I don't want the store proc to create a table having all records then crystal makes report by filtering. The all-record table could grow huge very quickly as more data is put in.
Thank you very much.Hi Peter
Follow these steps:
A. Following steps applies to the main procedure:
1. Create a main report which accepts the same fields as you want to pass to the stored procedure. (Note that this main report is not based off the procedure that you want to execute. Just get the data that you want to pass to the procedure. We will call the procedure in the subreport.)
2. Now create the no. of dynamic parameters that you want your user to choose the data from in the main report. (Lets assume that the user will select a single value.)
B. Following section applies to the subreport:
1. Add a subreport to the main report. This subreport will be based off your procedure. This will automatically add up the stored procedure parameters to the subreport.
2. Take care that in the procedure you define the datatype of the parameters same as the field's data type that you want to pass to the procedure. This will show up your stored procedure parameters while subreport linking.
3. Now link the main report to the subreport with each parameter. Uncheck the "Select data based on" dialog box while linking each parameter.
Hope this post solves your problem. i am sorry for sounding descriptive.
Regards
Nikhil Sabnis -
Getting data stored in ref cursor ( got from store proc in oracle) to excel sheet)
Hey, I am trying to Get data stored in ref cursor ( got from store proc in oracle) to excel sheet in a virtual folder using ssis.
I am getting errors and cant do it. If anyone can help meHi Nabin000,
The Oracle stored procedure doesn't work with SSIS source adapters such as OLE DB Source because the data provider doesn't provide metadata for the source adapter. To achieve your goal, you can use a Script Component as source to call
the Oracle stored procedure by using System.Data.OracleClient OracleDataReader, and get the rows and add them to the pipeline buffer. For more information, please see:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d0b3a1b-8792-469c-b0d1-f2fbb9e9ff20/dump-oracle-ref-cursor-into-ms-sql-staging-table-using-ssis
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/executing-an-oracle-stored-procedure-from-ssis?forum=sqlintegrationservices
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(VS.90).aspx
Regards,
Mike Yin
TechNet Community Support -
Issue with BPM while calling store proc
Hi All,
We are using BPM to execute/call the store procedure for look up. We are sending the correct request; bu we are not get the expected output form BPM during runtime. No issue with store proc ,we doudble checked
Is there any way to debug the BPM part of it. Plz advise Any bok or suggestion will be appreciated.
Thanks & Regards,
MohanIntegration Process monitoring:
https://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/ab3f538e-0d01-0010-07b7-802c90b67eec&overridelayout=true
Regards,
Manjusha. -
Hi folks, how do you write a store proc to return all tyre Speeds if no Speeds are selected, it won’t work with
IS NULL!
I have tried the following
@Speed = ' ' and kind of works i.e. the first search work perfectly, but when you change one of the other
dropdown list you get all the same results regardless of what you have selected, it’s like the other dropdowns lists don’t filter the data after the first search!
SQL
WHERE Width
= @Width and Product.Profile
= @Profile and Product.Diamete
= @Diamete and Product.Speed
= @Speed or @Speed
= ' '
and Suppliers.SupplierDistrict
= LEFT(@CustPostcode,2)
ORDER
BY Product.ProductUnitSalePrice
ASC
ASP
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="Width"
DataValueField="Width"
Height="27px"
style="margin-left:
0px"
Width="99px"
AppendDataBoundItems="True">
<asp:ListItem
Text="Width"
Value=""
/>
</asp:DropDownList>
<asp:DropDownList
ID="DropDownList2"
runat="server"
DataSourceID="SqlDataSource3"
DataTextField="Profile"
DataValueField="Profile"
Height="27px"
Width="97px"
AppendDataBoundItems="True">
<asp:ListItem
Text="Profile"
Value=""
/>
</asp:DropDownList>
<asp:DropDownList
ID="DropDownList3"
runat="server"
DataSourceID="SqlDataSource4"
DataTextField="Diamete"
DataValueField="Diamete"
Height="29px"
Width="97px"
AppendDataBoundItems="True">
<asp:ListItem
Text="Diamete"
Value
=""
/>
</asp:DropDownList>
<asp:DropDownList
ID="DropDownList4"
runat="server"
DataSourceID="SqlDataSource5"
DataTextField="Speed"
DataValueField="Speed"
Height="29px"
Width="99px"
AppendDataBoundItems="True">
<asp:ListItem
Text="Select All"
Value=" "
/>
</asp:DropDownList>
Bruceythis?
WHERE Width = @Width
and Product.Profile = @Profile
and Product.Diamete = @Diamete
and (Product.Speed = @Speed
or COALESCE(@Speed,'') = '')
and Suppliers.SupplierDistrict = LEFT(@CustPostcode,2)
ORDER BY Product.ProductUnitSalePrice ASC
and set default value as blank at your front end
ie
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource5" DataTextField="Speed"DataValueField="Speed" Height="29px" Width="99px" AppendDataBoundItems="True">
<asp:ListItem Text="Select
All" Value="" />
</asp:DropDownList>
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Schedule a store proc to run with different values
Hi ALL ,
I have a store Proc i need to schedule it using the sql agent that i can do but the requirement is to exec the same store proc for different values at same time .
like for eg i need to run the below same store proc for 3 different values at the same time.
exec getIPs 'US'
exec getIPs 'IND'
exec getIPs 'UK'
So for instance time is 02:30 am .
The Same Store Proc should exec for values like US,IND & UK . If the exec for one of the values fail it should still continue .
Like for eg if by chance due to some reason US fails it should move to next value IND in short continue with the exec.
These values US,IND,Uk am getting from a table called Countries .
Kindly help with this requirement.
Thanks
PriyaI am unable to test but you can try something like this,
DECLARE @COUNTRYID INT
SET @COUNTRYID = 1WHILE @COUNTRYID <= (SELECT MAX(COUNTRY_ID) FROM COUNTRY)
BEGIN
DECLARE @COUNTRY_CODE VARCHAR
BEGIN TRY
SELECT @COUNTRY_CODE = COUNTRY_CODE FROM COUNTRY WHERE COUNTRY_ID = @COUNTRYID
EXEC getIPs @COUNTRY_CODE
END TRY
BEGIN CATCH
INSERT INTO [dbo].[ERROR_LOG]
SELECT
GETDATE(),
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage
END CATCH;
SET @COUNTRYID = @COUNTRYID + 1
END
Regards, RSingh -
How to copy store proc from one schema to another
Hi I have store proc. and I want to copy that store proc from schema DATAMART_ADMIN to QAI_ADMIN ?
Can someone let me know how to do that ?
Thanks
JayWhy would you want to copy the procedure? Why not create a synonym in the target schema that points at the source schema?
If you do need to copy the procedure, you would have to take your CREATE PROCEDURE script and run it in the new schema. Ideally, this would come out of your version control system. Otherwise, any GUI should be able to generate a CREATE PROCEDURE script for you as will the DBMS_METADATA package.
Justin -
i have a store proc writen in oracle, it has a cursor and it is fetching into variables.
FETCH Jrecord into
v_projectID,
v_scounty,
v_county_pct,
v_existing_lane_cnt,
v_proposed_lane_cnt,
v_comnt,
v_comnt_typ;
the store proc works fine from oracle. i get data back as
john,23,56,67,543 wells way, etc....
but when i am calling it from the bean i am getting an error back on
TPRO_J= P_TPRO.executeQuery();
now do i call the name of the fields as in the database or use the variables to call. help please and i wonder if i should be giving alias for the columns
----------here is the bean--------------------------------------------
public Vector getRecordJ(String ProjectID){
ResultSet TPRO_J=null;
try{
System.out.println("a");
CallableStatement P_TPRO=conOrcl.prepareCall("{call getJrecord(?)}");
//assign the ? to the argument passed
System.out.println("b");
P_TPRO.setString(1,ProjectID);
//execute the query
System.out.println("c");
TPRO_J= P_TPRO.executeQuery();
//looping through the resultSet
System.out.println("d");
while (TPRO_J.next()){
System.out.println("e");
//create an instance of the class
Conn JItems = new Conn();
// set it to the Bean
JItems.setCounty(TPRO_J.getString("county"));
JItems.setCountyPct(TPRO_J.getInt("county_pct"));
JItems.setexistingLane(TPRO_J.getInt("existing_lane_cnt"));
JItems.setproposed_lane(TPRO_J.getInt("proposed_lane_cnt"));
JItems.setcomnt(TPRO_J.getString("comnt"));
JItems.setcomntType(TPRO_J.getString("comnt_typ"));
//add the object to the vector
V_itemsJ.addElement(JItems);
}catch(SQLException w){
System.out.println(w.getMessage());
//returning the vector
return V_itemsJ;
i am getting a message in the dos prompt
a
b
c
no resultset was produced
it stops here
help and thanxSince your output stops at "c", the error is occurring before printing "d". That is your line TPRO_J= P_TPRO.executeQuery();
Try changing your prepareCall like this:
CallableStatement P_TPRO = conOrcl.prepareCall("{call getJrecord ? }");
Note that the ? is not in parenthesis. -
How to insert past record after updating the master table in history table through store PROC
Master Table
Party Status
A Active
B Inactive
C Active
D Inactive
Duplicate Table
Party Status
A Active
B Active
C Active
D Inactive
Updated Master Table
Party Status
A Active
B Active
C Active
D Inactive
Party History Table
B Inactive
I have two table one master and another duplicate I need to update master table based on duplicate table insert the record which updated into Party history table as shown above. need help to write store proc.Check MERGE syntax in BOL (example D). There should be a sample with output, e.g.
insert into PartyHistory (Party, [Status])
select Party, [Status] FROM
(MERGE Master M using Duplicate D on M.[Party]=D.[Party]AND M.[Status]<>D.[Status]
WHEN MATCHED THEN UPDATE
SET [Status] = D.[Status]
OUTPUT Deleted.[Party], Deleted.[Status], $Action) AS Changes (Party, [Status], Action) WHERE Action = 'UPDATE'
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to send sortorder info to Store Proc
Hi
I have a Store Proc in SQL Server
Now i want to give the Sort Order dynamically for this Store
Proc.
When i am trying to send the SortOrder, in the query it is
saying that i cant give the parameter.
It is forcing me to give field names directly.
i cant able to give the Order by dynamically.
how can i do this.?
i need to change the Order By dynamically in Store Proc.
i can send the paramter to Store Proc, but its not accespting
in the query.Try this stored procedure.
CREATE PROCEDURE [dbo].[myProcedure]
@OrderParam VARCHAR(20)
AS
Declare @sQuery as VARCHAR(100)
SET @sQuery = 'select * from myTable order by ' +
CAST(@OrderParam AS VARCHAR(15))
EXEC(@sQuery)
GO
Thanks
Sankalan
(www.mindfiresolutions.com) -
Data Service Not showing all the out param values in Oracle Store proc call
Hi,
I have imported a Oracle stored proc which takes 3 input params and gives 33 out params.
While testing the Data Service , it is showing only the First 3 out params.
I tried the same request thrught JDBC code and it is showing results for some of the other params.
Is this any DSP issue ?
Thanks
GkumarOpen a case with Customer Support and ask for the patch on CR295750.
-
How to break down a huge resultset from a store proc
Hello All:
First of all, I posted this question on Spring forum: http://forum.springsource.org/showthread.php?115721-how-to-catch-SQL-exception-when-using-JDBCTemplate in hope to see if there is a Spring solution since my project is based on Spring framework.
I hope this is not a cross post, since I want to know how I can achive the same by using generic JDBC.
My issue is that I need to run a stored proc, with certain parameters in place the resultset is huge. I can't send this back directly to the client. With Spring APIs it seems solution is not simply, someone suggested Spring batch. That require a steep learning curve and might turn out to be a overkill. I am thinking maybe generic JDBC can help, and this is what I want to do
while(rs.next()){ //count 100 records and send to a queue } // a consume stay put to consume the records and discard resource to avoid OutOfMemory
Will the above design work? since I didn't use too many delicated JDBC in the past, you might be able to help me catch some pitfall there.
Thanks, Johnthanks EJP. I figured out that I was barking at the wrong tree. I don't really need Rowset or the likes. I only need to wrap a bunch records each time, put it into a blocking queue so that the pace is well coordinated during the iteration. A consumer reads from the queue and shoot them to a message broker.
Nevertheless, its good to read some javax.sql stuff. Thanks.
Maybe you are looking for
-
Agent problem in Payment Release Workflow
Hi WF PRof's, I am using the standard workflow WS00400012 for Payment Release.I am using two level approval process.If the invoice amount is less than 20,000 it should goto approver X and if it more than that it should do for X first and then to Y
-
.mp4 video imports but won't play/edit?
I'm trying to edit some .mp4 clips in my iMovie 11 and am having problems. They import fine, but when i try to edit them, play them, etc all I get is the audio but only the first frame of video. There's also a small yellow circle in the bottom left c
-
Calling a subpanel, pops up in own window instead of sub panel when there is an error
Hi all. I am working on my first real LV project for my company, and I am having some problems. The main one right now happens when I am trying to call a subVI into a subpanel. It shows up in the subpanel just fine when the program starts, but when t
-
Ok so this has been bugging me for awhile a so far I've ignored it because it's not a huge deal but I have a type writer effect using the code below, the problem is I want, when a button is clicked, for it to finish completely. Just jump right to the
-
Screen exit or screen badi for me57 subscreen
Hi, After going to ME57 and giving plant we have got list of PR's,now If I select one PR and click on assign automatically button I am getting popup with possible source list , here I will have to add some extra fields to the popup screen for which I