Stored procedure Update Statement missing column dynamic creation
Hi All,
Here is my scenario. I am having Stored procedure with 5 parameters for particular table. But table schema is having only 3 columns. Is there any way to create 2 missing columns dynamically while Stored Procedure is running?. How can we handle the missing column
exception. Please help me.
Thanks,Sakthi
Thanks and Regards, Sakthi
Hi All,
Here is my scenario. I am having Stored procedure with 5 parameters for particular table. But table schema is having only 3 columns. Is there any way to create 2 missing columns dynamically while Stored Procedure is running?. How can we handle the missing column
exception. Please help me.
Thanks,Sakthi
Thanks and Regards, Sakthi
Very bizarre requirement - surely you meant Temporary Table.
For physical table, it would be a good idea to check if column already exists then ADD columns as per Uri Dimant's post.
if exists(select * from sys.columns
where Name = N'columnName' and Object_ID = Object_ID(N'tableName'))
begin
-- Column Exists
end
web: www.ronnierahman.com
Similar Messages
-
Running a SQL Stored Procedure from Power Query with Dynamic Parameters
Hi,
I want to execute a stored procedure from Power Query with dynamic parameters.
In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
Name_Value = Name_Parameter{0}[Value],
I have tried like below but it is not working.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
Can anyone please help me with this issue.
Thanks
DileepHi,
I got it. Below is the correct syntax.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
Thanks
Dileep -
I have a stored procedure that dynamically creates a pivot query. The procedure works and returns the correct data. Now I have a requirement to show this data in reporting system that can only pull from a table or view. Since you can not
create a dynamic query in a view I tried to do a select from using openquery.
Example 'Select * from OpenQuery([MyServername], 'Exec Instance.Schema.StoredProcedure')
I get the error back "the linked server indicates the object has no columns". I assume this is because of the first select statement that is stuffing the variable with column names.
CODE FROM PROCEDURE
Alter PROCEDURE [dbo].[Procedure1]
AS
BEGIN
SET NOCOUNT ON
Declare @cols nvarchar(2000),
@Tcols nvarchar(2000),
@Sql nvarchar (max)
select @cols = stuff ((
Select distinct '], ['+ModelName + ' ' + CombustorName
from CombustorFuel cf
join Model m on cf.modelid = m.modelid
join Combustors cb on cf.CombustorID = cb.CombustorID
where cf.CombustorID > 0
for XML Path('')
),1,2,'')+']'
Set @Tcols = replace(@Cols, ']', '] int')
--Print @Tcols
--Print @Cols
Set @Sql = 'Select GasLiquid, FuelType, '+ @Cols +'
from
Select GasLiquid, FuelType, ModelName+ '' '' +CombustorName ModelCombustor, CombFuelStatus+''- ''+CombFuelNote CombFuelStatusNote
from Frames f
join Family fa on f.Frameid = fa.frameid
join Model m on fa.FamilyID = m.FamilyID
join CombustorFuel cf on m.Modelid = cf.modelid
Join Combustors c on cf.CombustorId = c.CombustorID
join FuelTypes ft on cf.FuelTypeID = ft.FuelTypeID
where cf.CombustorFuelID > 0
and CombustorName <> ''''
) up
Pivot
(max(CombFuelStatusNote) for ModelCombustor in ('+ @Cols +')) as pvt
order by FuelType'
exec (@Sql)Then again, a good reporting tool should be able to do dynamic pivot on its own, because dynamic pivoting is a presentation feature.
SSRS Supports dynamic columns: Displaying Dynamic Columns in SSRS Report
SQL Reporting Services with Dynamic Column Reports
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Displaying and reading are two very different things.
#1) SSRS Needs a fixed field list on the input side to know what what to make available in the designer.
#2) SSRS cant read "exec (@Sql)" out of a proc, even if there is a fixed number of columns (at
least it can't use it to auto build the field list from the proc)
I use dynamic SQL in my report procs on a fairly regular basis and I've found it easiest to simply dump
the results of my dynamic sql into a temp table at the end of the procs and then select from the temp table.
Basically, Erland is correct. Stop trying to pivot in the query and let SSRS (or whatever reporting software you're using) handle it with a Martix.
Jason Long -
Block based on Stored Procedure - Update Changed columns only
If I were to base a block on stored procedures that includes an Update procedure but only update SOME of the updateable columns, what happens?
Does the Form send to server ONLY
1) The rows that were updated
2) The columns that updated
3) All columns in the row being updated regardless of whether they were updated
Is the correct answer 1) + 2) or 1) + 3)
Please help.
ThanksHello,
<p>There is another example here</p>
Francois -
Calling a stored procedure with argument as column name
hi
i am calling a stored procedure mapping_audit_errors_inserts
whose definition is as follows
PROCEDURE mapping_audit_errors_inserts (
in_ma_seq_id IN ETL_MAPPING_AUDIT_ERRORS.ma_seq_id%TYPE,
in_etl_stage IN ETL_MAPPING_AUDIT_ERRORS.etl_stage%TYPE,
in_sqlerrcode IN ETL_MAPPING_AUDIT_ERRORS.sqlerrcode%TYPE
IS
BEGIN
mapping_audit_ora_errors (in_ma_seq_id,
in_etl_stage,
in_sqlerrcode,
get_error_message (in_sqlerrcode)
END;
now i need to call this procedure as
mapping_audit_errors_inserts(MA_SEQ_ID.currval,1,v_error_code)
[ v_error_code:=SQLCODE;]
it is giving error as
PLS-00201: identifier 'MA_SEQ_ID.CURRVAL' must be declared
can anyone calrify me on this.
ThanksAnwar is likely correct about the reason for your error. The other possibility is that the owner of the procedure calling mapping_audit_errors_inserts does not have SELECT on the sequence granted directly to them.
However, even after creating the sequence, if the session calling the procedure has not got a value from the sequence prior to trying to use CURRVAL, you will get:
SQL> CREATE PROCEDURE p(p_id IN NUMBER) AS
2 BEGIN
3 DBMS_OUTPUT.Put_Line('ID is '||p_id);
4 END;
5 /
Procedure created.
SQL> DECLARE
2 l_no NUMBER;
3 BEGIN
4 SELECT ma_seq_id.CURRVAL INTO l_no
5 FROM dual;
6 p(l_no);
7 END;
8 /
DECLARE
ERROR at line 1:
ORA-08002: sequence MA_SEQ_ID.CURRVAL is not yet defined in this session
ORA-06512: at line 4And, just to reinforce Anwar's point about selecting it into a variable, if you try to pass CURRVAL to a procedure, you will get:
SQL> DECLARE
2 l_no NUMBER;
3 BEGIN
4 SELECT ma_seq_id.NEXTVAL INTO l_no
5 FROM dual;
6 p(ma_seq_id.CURRVAL);
7 END;
8 /
p(ma_seq_id.CURRVAL);
ERROR at line 6:
ORA-06550: line 6, column 16:
PLS-00357: Table,View Or Sequence reference 'MA_SEQ_ID.CURRVAL' not allowed in
this context
ORA-06550: line 6, column 4:
PL/SQL: Statement ignoredTTFN
John -
Question about MySQL, JDBC, SQLJ, Stored procedure & callable statements
Hi, there. I'm using j2sdk1.4.1_01 and MySQL ver 12.18 Distrib 4.0.12, and when I try to install a store procedure, it throws the following message:
SQLException: Stored procedures not supported: {call sqlj.install_jar('blah...blah...MyProject-20031206.jar', 'routines_jar', 0)}
Who's is not supporting store procedures here? Java or MySQL? What can I do?
The book and sample code I'm using as a reference mention that "the sample code assumes that the DBMS already stores the built-in SQLJ procedure sqlj.install_jar, which loads a set of classes written in the Java programming language in an SQL system". Now my question is: the "SQLJ procedure sqlj.install_jar" is something extra that I need to install or it has nothing to do with the problem?
Is it true that MySQL does not support stored procedures? Thank you in advance for any hint or suggestion.
Regards,
Hector.Who's is not supporting store procedures here? Java or
MySQL?MySQL.
What can I do?1. Don't use stored procedures.
2. Use a database that supports stored procedures.
3. Wait for the release of MySQL that does support stored procedures. -
Update a site column dynamically to Approval Status
Hello all this is what I have;
InfoPath form with Form Status field (Form Status promoted to SP form library as site column) form switches to read only view when Form Status = Approved
SharePoint form library set to require content approval
Copied and modified OOB Publishing Approval workflow with Association column, Form Status added,
As it stands, the work flow runs and updates the list item, Form Status, to Approval Status, unfortunately Approval status is set beck to pending (which is correct behavior I assume) I need some help! can I insert the Update list item action in the workflow
task steps? I want Form status to start as pending and then reflect whatever Approval Status value is. This is my first attempt at modifying an OOB workflow, is this the right approach?
Thanks for any help, I have tried several solutions but I am definately missing something. Should the workflow restart on item change? should I have versioning turned on? all I am trying to accomplish is have the form switch to read only if it's approved and
then if for some reason someone needs to make a change I need Form Status and Approval Status to have the same value.Hi,
If you only want to approve content, you can enable content approval.
If you want to manage versions, you need to enable content approval first and then enable version.
More information:
Require approval of items in a site list or library
Enable and configure versioning for a list or library
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Create a trigger/stored procedure to set one column equal to another
Hey guys,
I have two columns in a table, and when column A is updated or inserted, I need the database to automatically update column B (in the same table) to be equal to that. I can't create a trigger AFTER INSERT OR UPDATE, because it's the same table and it gives me the mutating tables error.
Any help is appreciated.How have you defined your trigger? It sounds like you should just be able to do
BEGIN
:new.columnB := :new.columnA;
END;I assume if you are getting a mutating table error that your trigger is trying to query the table. I don't see a need to query the table.
Justin -
Conversion Error - when Stored Procedure Execution Statement line is broken
Hi ,
I am getting data type conversion Error whenever any value of a multivalued parameter is brought to the next line(or breaking up of the EXEC command to multiple lines, by enter key or tab.
On executing SP_ABC with second value for @parm3UID in the next line-
THE ERROR IS -
Similarly when date value for @parm4Date is throwing when SP Execution statement is
Kindly help me resolving the issue.
Thanks in Advance!!
Mridhula
Mridhula.SOh sorry Patrick , here is the code-
when second value of @parm3UID is entered to the next line-
exec dbo.SP_ABC @parm1UID=N'DF617C6D-F68F-E411-9CAE-180373C4FF6B',
@parmProgram=N'Null', @parm3UID=N'AA8AC32B-2AC5-E311-80CB-005056B2487C,
661E59C1-29C5-E311-80CB-005056B2487C',
@parm4Date='2015-01-05 00:00:00'
For the above code Error displayed is
Conversion failed when converting from a character string to uniqueidentifier.
when Date value @parm4Date is broken-
exec dbo.SP_ABC @parm1UID=N'DF617C6D-F68F-E411-9CAE-180373C4FF6B',
@parmProgram=N'Null', @parm3UID=N'AA8AC32B-2AC5-E311-80CB-005056B2487C,661E59C1-29C5-E311-80CB-005056B2487C',
@parm4Date='2015-01-05
00:00:00'
For the above code Error displayed is
Msg 8114, Level 16, State 1, Procedure SP_ABC, Line 0
Error converting data type varchar to datetime
When the codes come in a single line exec statement works fine.Only issue is when a carriage return or tab comes in between. Please let me know for further details.
Thanks!!
Mridhula.S -
Execute Stored Procedure SQL Statement with Parameter from Cell
I would like to know if there is a way to pass the parameters to SQL Statement of Power Query. For example, I have a SQL Statement as follows:
EXEC [dbo].[spReportBuilder]
@Report = N'Revenue Summary',
@Year = N'2014',
@Period = N'11'
I would like to know if it is possible to pass the @Report, @Year, @Period values from cells in the workbook, preferably without vba.
Thanksrtisserand,
Here is the M code:
let
IDValue = Excel.CurrentWorkbook(){[Name="YearTable"]}[Content],
Source = Sql.Database("localhost", "AdventureWorks2012", [Query="EXEC [dbo].[spReportBuilder] @Report = N'Revenue Summary', @Year = N'" & Number.ToText(IDValue[ID]{0}) & "', @Period = N'11'"])
in
Source
Some notes:
You have to reference the excel query from another step in the query or you will get the following error:
Formula.Firewall: Query <>something<> references other queries or steps and so may not directly access a data source. Please rebuild this data combination.
I only did the parameter for one value.
Hope this helps.
Reeves
Denver, CO -
Master Detail Form - Update Statement for Column in the Detail Section
Hello,
I've posted a demo application to apex.oracle.com
Application# 49298
Application Name: Street_Inventory
Basically, on page 3 I have a Master Detail Form. In the Detail section, I want the value of On_hand to save to table ITEMS. Here's my code below.
SOURCE
select
"CONSUME_DETAIL"."CONSUME_DETAIL_ID",
"CONSUME_DETAIL"."CONSUME_HEADER_ID",
"CONSUME_DETAIL"."ITEM_ID",
"CONSUME_DETAIL"."CONSUMED_QUANTITY",
("ITEMS"."ON_HAND" - "CONSUME_DETAIL"."CONSUMED_QUANTITY") as "ON_HAND"
from "CONSUME_DETAIL",
"ITEMS"
where "CONSUME_HEADER_ID" = :P3_CONSUME_HEADER_ID
and "CONSUME_DETAIL"."ITEM_ID"="ITEMS"."ITEM_ID"
UPDATE INVENTORY PROCESS
UPDATE ITEMS
SET ON_HAND = :P3_ON_HAND - :P3_CONSUMED_QUANTITY
WHERE ITEM_ID = (select ITEM_ID
from CONSUME_DETAIL
where CONSUME_DETAIL_ID = :P3_CONSUME_DETAIL_ID);
My code isn't working. What am I doing wrong?WReed,
The first thing I see "off the bat" is that you don't have items named P3_ON_HAND and P3_CONSUMED_QUANTITY which are referenced in your code. Although it's possible to do what you want with just SQL, I updated your code with a little PL/SQL to make it easier to understand...
As you'll see the problem now is that the design/db model is not quite right as your getting a too many rows error.
Regards,
Dan
http://danielmcghan.us
http://sourceforge.net/projects/tapigen -
Call stored procedure on a different db (dynamically)
Hi All,
I would like to call a sp on a different db. I know how I can hard code the db name in this case @dev.
tablespace.packagename.procname@DEV();
This works just fine but I would like to be able to pass the dbname into the call to the sp. ie when I move to UAT and prod
declare
dbname varchar2(10):='@UAT';
begin
id.packagename.procname:dbname();
end;
Bind variables dont work in this case. What is the correct way of achieving this?
Thanks in advance,
Luke (newbie)1001059 wrote:
Hi All,
I would like to call a sp on a different db. I know how I can hard code the db name in this case @dev.
tablespace.packagename.procname@DEV();
This works just fine but I would like to be able to pass the dbname into the call to the sp. ie when I move to UAT and prod
declare
dbname varchar2(10):='@UAT';
begin
id.packagename.procname:dbname();
end;
Bind variables dont work in this case. What is the correct way of achieving this?
Thanks in advance,
Luke (newbie)I am not sure I would classify as "correct", but what I did was effective.
my sql always used the literal "@REMOTE" & prior to using the sql I would estable a private DBLINK
such that "REMOTE" was directed to the desired database. -
Stored Procedure to update Ids
Hi,
I want to write a stored procedure to update IDs in detail table by matching description from master table i.e.
TabMaster
Col1: 1 2 3 4 5 6 7 8
Col2: A B C D E F G H
TabDetail
Col:
Col2: D B C E D A A B G H C
Please Help!
Thanks in advanceNow sure what you are really after, but it looks like you may only need a correlated update statement. This statement can then be put inside a stored procedure:
UPDATE TabDetail TD
SET Col = (
SELECT Col1
FROM TabMaster TM
WHERE TD.Col2 = TM.Col2
)This will update ALL the rows in the TabDetail table. However if you need to restrict the rows to be updated you can always add on a WHERE clause. -
Dynamic SQL and Oracle stored procedures
Does anybody has any experience with invoking an Oracle stored procedures
with output parameters, using dynamic SQL from Forte?
Thanks,
DimitarI would be interested. We are currently using a homegrown DataMapper architecture with the Microsoft OracleClient. I would like to move to ODP.Net once a production version supporting ADO.Net 2.0 is available. After that, I would then like to look at using an off the shelf persistence framework such as EntitySpaces, NHibernate or IdeaBlade's DevForce.
-
How to return varied no.of columns from Stored Procedure?
Hi All,
I have situation where I need to return with columns which will keep changing. At any given point of time I will be returning 10 columns. But there are some conditions where I need to add multiples of 4 no.of columns.
Ex: Always 10 columns.
If condition1
return 10 + 4 columns
if condition2
return 10 + 4 + 4 columns
How can I handle this?
Can any one help me here.
Thanks
VikramChange the stored procedure to a single column set return type like returning nulls if column is not applicable.
Alternate, split the sp to single column set sp-s.
You can get the returned column set by SELECT TOP(0) * INTO spxColumns FROM OPENQUERY..... method:
http://sqlusa.com/bestpractices2005/selectfromsproc/
http://www.sqlusa.com/bestpractices/select-into/
Note, however, the OPENQUERY method is not completely clean.
Kalman Toth Database & OLAP Architect
Free T-SQL Scripts
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Maybe you are looking for
-
Error while upload a file in GLPLUP
hi When i try to upload a file in GLPLUP , iam getting this error, please forward your solutions to solve this. Value 000 in field "Period" is less than 1 Message no. K9019 Diagnosis In either the initial transaction screen or within layout definiti
-
How to delete a perticular node from xml file using java code
Hii All, Now i am trying to delete a perticular node from xml file.Like... XML file: <Licence> <SERVER> <was id="1">1</was> <was id="2">2</was> </SERVER> </LICENCE> I am working in messaging service using JABBER framework with whiteboard facility. He
-
How do I save pictures from my library to the external sd card on my droid x2
How do I save pictures from my library to the external sd card on my droid x2?
-
My points are not displayed correctly
Hi, My SDN points are actually 282. But now it's displaying 0. Is it some technical problem or is there some reason behind deleting my points. I request the moderators to look at this once. Thanks, Sri. Problem Solved Edited by: Sri on Dec 7, 2009 11
-
REQUEST new GOP / EUFI bios for MSI R9 290 GAMING 4G
MSI R9 290 GAMING 4G S/N: 602-V308-02SB1401020608 Link to current vbios: _https://www.dropbox.com/s/kn5qoj4kujhyx8t/Hawaii.rom?dl=0 screenshot of CPU-Z: edit: i may have put this in the wrong section..