Is There A Way To Know The Condition In An Update/Delete Command Inside A SP?
May 7, 2008
Hi to all:
I'm trying to make a sp who generates an export string for everey sql command, for example: Insert, update and delete. In the case of Insert I just have the sp, but in "update" and "delete" commands... how can I know the conditions?..
UDTATE DemoTable SET DemoField=77 WHERE (Condition1 AND Condition2)
....may I use a comparative with 'updated' table?, please help me with your ideas
Hi, I tried to use the RETURN_VALUE of a stored procedure in updata / delete commands with a sql-datasource and a stored procedure. The thing works fine with the insert command.But it fails with "too many arguments..." in delete / update. I also tried to handle the updating event like this: protected void sqldsReportSelect_Updating(object sender, SqlDataSourceCommandEventArgs e) { SqlParameter sqP = new SqlParameter("RETURN_VALUE", SqlDbType.Int); sqP.Direction = ParameterDirection.ReturnValue; e.Command.Parameters.Add(sqP);} It brings the same error. Do I make something wrong or is this a bug? Regards Manfred
We have SS2K5 source and DB2 Target. I downloaded and installed MS OLE DB provider for DB2. It is configured correctly. The data insert works fine. But I am having problem with update/delete on DB2 when passing string parameters.
The OLEDB command works fine when I hard code the values: delete from TableName where Col1='abc' and Col2='xyz'
But when I use parameters the package executes successfully, but the data is not delete on DB2.
Any one having similar experience or solution for this is really appreciated.
i've read the transact-sql command, i known that the select command use to retrieve many fields from many tables with one command select * from table1,table2 yes, but i ' ve not seen the way to add,delete or update those fields from those tables with one command...
Is it possible? why? I don't have any idea , can u help me I want to know the sql commands , if it's possible
I am having a sql query task to fetch a maximun number. Example output : 102. After that I have a for each container to return files from a particular location. Files in the location are for example KAS.JN.101, KAS.JN:102, KAS.JN.103, KAS.JN.104. I want to lpop over only the files which have the ending greater than the maximum number returned from the sql query. In this case, the for each container must only loop over 103, 104. Chow to pass this condition to the container ?
I want to edit(update,delete,insert) target table activity from front end for that I took grid view and that grid all activity come of single student studenid(unique key for each student) that you see design below like this
that activity present in target table that come as check in check and that activity not select student from activity activity table that come unchecked
I want to update above information means unchecked alredy check data should delete and new check data add , already check data update
I have use merge statement but problem is that at single time only one row execute that is check because data come from data gridview.
i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString() test.InsertCommandType = SqlDataSourceCommandType.Text test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) " test.InsertParameters.Add("roll", TextBox1.Text) test.InsertParameters.Add("name", TextBox2.Text) test.InsertParameters.Add("age", TextBox3.Text) test.InsertParameters.Add("email", TextBox4.Text) test.Insert() i am using UPDATE command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString() test.UpdateCommandType = SqlDataSourceCommandType.Text test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll 123 " test.Update()but i have to use the SELECT command like this which is completely different from INSERT and UPDATE commands Dim tblData As New Data.DataTable() Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True") Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn) Dim da As New Data.SqlClient.SqlDataAdapter(Command) da.Fill(tblData) conn.Close() TextBox4.Text = tblData.Rows(1).Item("name").ToString() TextBox5.Text = tblData.Rows(1).Item("age").ToString() TextBox6.Text = tblData.Rows(1).Item("email").ToString() for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me
I have written a merge Statement where i am facing trouble to delete the data basing on Where Clause Condition.
1) Case 1 : For example i have inserted Data from Source to Target based on Date Key Condition.Take an Instance 10 Records Inserted. 2) Case 2 : For example some changes in the records and it has been updated through the Merge Statement . 3) Case 3 : For the Same Date key based on Conditions now three records has came and need to be inserted and rest should be deleted for that Date Key.
How i need to proceed on this before 10 records are not getting deleted and new records adding for that one
My Example Code :
MERGE INTO TargetTable AS Target USING ( SELECT DISTINCT Col1, Col2 FROM Table1 AS cga ) ON dad.AnchorDate = CASE
I have the following scenario : CustomerDetail customerid customername status app_no
[status = 0 means customer virtually deleted]
CustomerArchive archiveno [autoincrement] customerid customername status
At the end of the month, I have to physically delete customers. I have written two stored procs:
proc1 create proc spoc_startdeletion as declare @app_no int select @app_no = (select app_no from customerdetail where status=0) EXEC spoc_insertcustomerarchive @app_no -- After transferrin, physically delete delete from customerdetail where status=0
proc2 create proc spoc_insertcustomerarchive @app_no int as insert into customerarchive(customerid,customername,status) select customerid,customername,status from customerdetail where app_no = @app_no
It works fine if there is only one row with status=0, however the problem is that when there are multiple rows in customerdetail with status=0, it returns 'Subquery returned more than one value'
How can i transfer multiple rows one by one from the customerdetail to customerarchive and then delete the rows once they are transferred.
I have around 3 tables having around 20 to 30gb of data. My table A related to table B by a FK and same way table B related to table C by FK. I would like to delete all rows satisfying certain condition from table A and all corresponding related records from table B and C. I have created a query to delete the grandchild first, followed by child table and finally parent. I have used inner join in my delete query. As you all know, inner join delete operations, are going to be extremely resource Intensive especially on bigger tables.
What is the best approach to delete all these rows? There are many constraints, triggers on these tables. Also, there might be some FK relations to other tables as well.
can anyone help to create storeprocedure in SQL SERVER 2000? the case is like this: i have one table call [TIMETABLE] which contains these fields:ID,start_time,finish_time,subject_code,venu e and another table call [attendant_sheet] has these following fields:ID(which should be from TIMETABLE),student_id,subject_code,status,date.
and the storeprocedure will works like this:
if the time(system time) has pass the finish_time on TIMETABLE table then insert the related field into attendant_sheet. and then update the status field to 'absent' and the student_id should be get it from another table call [enrolment] who havent take their attendance and enrols related subect?
Table A - data example Idno Entity Flag 1 1 y 2 1 n 3 1 y 4 1 y
Table B - data example Idno Entity 1 1 2 1 3 1
Table C - data example Idno Entity 4 1
I want to update the value flag in table A.Update flag from n to y if idno A in table B and and idno A not in table C, so from table A above, first record and 3rd record remain unchange but 2nd record, flag will be changed from n to y. 4th record where idno A not in table b and in Table C so flag will change from y to n. is it possible, or do i need to use the "fetch" method to compare record by record.
IF EXISTS ( SELECT * FROM empList WHERE (unit = 9)
) begin
update [dbo].[empList] set unit = CASE WHEN SELECT na,empID, unit FROM empList WHERE (empID IN (111, 222, 333, 555)) AND (unit = 9)) then '4' else t.fld1 end
I wanted to update Catrgory coulmn of all records in the Master table with the Value of LastUpdate of the CategoryTable the where the ID of the both the table are same
Update WACTS_Inventory_Part_Loc_Tbl SET WIPLT_Part_New_Qty = WIPLT.WIPLT_Part_New_Qty + tmp.MATIN_QTY FROM
WACTS_Inventory_Part_Loc_Tbl WIPLT
INNER JOIN
Temp_MatIn_Data tmp
ON
WIPLT.WIPLT_Part_Number_MSBA=tmp.PARTS_ShortID
WHERE
WIPLT.WIPLT_Location_Code='MF'
I have a Problem with this satment becoz my Temp_Matin_Data_Tmp table contains two records with the same PartNumber that is (ShortId) and the two records have two different quantities.
The WACTS_Inventory_Part_Loc_Tbl has only one Part NUmber Record and the key is the PartNUmber and Location_Code.
Now when the Update Satement runs it updates the qty only from the first record of the temp table and does not update the quantity of the second record from tne source table.
hi, I want to ask how I want update my table using a multiple condition.My table format is like this:
IC_NO F05 F07 F08 F09 Ind
123
452 C
654 852
P
125
A
526 C
What I want to do is:
IF Ind = C, F05 <> NULL then IC_NO = F05 IF IND = C, F05 = Null and F09 <> Null then IC_NO = F09 IF IND = P, F05 <> Null and F07 <> Null then IC_NO = F07 IF Ind = A, F05 = Null and F08 <> Null then IC_NO = F08
What's the best way to debug the SQL commands with parameters? My Formview performs the INSERT and EDIT commands fine -- and I can see the results in the tables. However, my Delete command crashes -- see the error below. I assume that the problem is a formatting issue with an input parameter -- i see there are equality tests for the parameters before the delete is allowed -- How Can I look at these parameters to inspect them? All the types on the paranmeters look fine to me!! ---Jim
Server Error in '/GVOps4' Application.
Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
Why cannot I use alias in delete command when I join two table.
My query is as follows. delete from ikw_indexed_form_approved where exists(select * from ikw_router where ikw_indexed_form_approved.ikw_subscription_id=ikw_ subscription_id and ikw_indexed_form_approved.ikw_indexed_name='centra al corp' and ikw_indexed_form_approved.content_code='html' and ikw_indexed_form_approved.ikw_subscription_id=1)
if I use like this it gives me an error delete from ikw_indexed_form_approved A where exists(select * from ikw_router where A.ikw_subscription_id=ikw_subscription_id and A.ikw_indexed_name='centraal corp' and A.content_code='html' and A.ikw_subscription_id=1)
I am using SQL 6.5. I have a master table which is referenced by more than 35 tables. When I try to delete a record from the table, i am getting this message
Msg 431, Level 16, State 0 Unable to bind foreign key constraint. Too many tables involved in query.
SQL 6.5 maximum 31 foreign key references. I was wondering is there any way to delete those records. (i don't want to drop the foreign constraints)
SQL 7.0 supports maximum 63 foreign key references.
I am currently in the process of writing an INSERT/UPDATE trigger in SQL 2012, the scenario is, I have a table called Quote, what I want to happen is when a record gets added to the table with a field called Approved, populated with a value or a record gets Updated and the Approved field gets populated I want the trigger to execute a stored procedure, passing through a value from a field called Account within the Quote table as a variable. I know I can achieve the action using one trigger "AFTER INSERT, UPDATE" but I am struggling on forming the rest of the trigger.
UPDATE #TempTableESR SET CTRLBudEng = (SELECT SUM(Salaries) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudTravel = (SELECT SUM(Travels) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudMaterials = (SELECT SUM(Materials) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudOther = (SELECT SUM(Others) from ProjectBudget WHERE Project = @Project)UPDATE #TempTableESR SET CTRLBudContingency = (SELECT SUM(Contingency) from ProjectBudget WHERE Project = @Project)above is the UPDATE command i am using in one of my stored procedures. I have to SELECT from my ProjectBudget table 5 times to update my #TempTableESR table. is there an UPDATE command i can use which would let me update multiple fields in a table using one SELECT command?
Someone told me that I couldnt update the global variavel inside a dataflow... but i need to have some solution to do that... :-(
I crate my identity column manually based on a global variable... and it works perfect, but in one dataflow I have to insert 2 times in the some table... so... in the second time my identity will be GlobalVariavel + increment of the first time rows inserted...
how can I save this increment in the dataflow? How can I count the rows inserted in the first time do use it in the second time i save Data to the some table??
i need to dyanamically generate my SQL commands so to do that i am generating sqldatasource commands programmatically rather declaratively. SELECT commands seems to work fine but DELETE isnt doing anything, here is my code:
SqlDataSource sdsConsultant = new SqlDataSource(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { loadDataSet(); //it just loads dataset used by formview initializeSDS(); }
//SELECT sdsConsultant.SelectCommand = "SELECT * FROM Consultants WHERE (id=@id)"; QueryStringParameter id = new QueryStringParameter("id", "id"); sdsConsultant.SelectParameters.Add(id);
//DELETE sdsConsultant.DeleteCommand = "DELETE * FROM Consultants WHERE (id=@id2)"; QueryStringParameter id2 = new QueryStringParameter("id2", "id"); sdsConsultant.DeleteParameters.Add(id2);
I am presently using 'tablediff' utility of SQLServer 2005 to compare tables located on two different servers. My real intension is to backup data from Serv1 to Serv2, except that I wish to update the tables on server2 with only newly inserted rows and updated rows and NOT deleted rows.
In short, I want the final .sql file generated by the tablediff utility to contain only 'Insert' and 'Update' statements and NOT 'Delete' statements.