I have dataset which has max(column) and between_sale_dates columns So I would like to update those columns. CustomerNo and Sales_date are important . This group by for these 2 colums. I can write a sproc but How can I do with SSIS?
IDBuyDotComPriceCompanyIDShadowOf AB CIRCLE PRO199.99203 AB CIRCLE PRO-b2199.99203AB CIRCLE PRO AB CIRCLE PRO-TB249.99344AB CIRCLE PRO AB CIRCLE PRO-TB-S10344AB CIRCLE PRO
I need to update the price of an item where the CompanyID is 344 and the ShadowOf is not null. The value in ShadowOf is the same as the ID that I want to get the BuyDotComPrice for. It should be simple, but I keep getting errors.
I am trying to update a users status from Pending to either Approved or Rejected. I created the following handers to update me db by I keep getting a syntax error. What am I doing wrong? public partial class admin_beta : System.Web.UI.Page{ protected void ApproveButton_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=TECATE;Initial Catalog=subscribe_mainSQL; User Id=maindb Password=$$ricardo; Integrated Security=SSPI"); SqlCommand cmd = new SqlCommand("UPDATE [main] ([status]) VALUES (@status)", conn); conn.Open(); cmd.Parameters.AddWithValue("@status", "Approved"); int i = cmd.ExecuteNonQuery(); conn.Dispose(); } protected void DenyButton_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=TECATE;Initial Catalog=subscribe_mainSQL; User Id=maindb Password=$$ricardo; Integrated Security=SSPI"); SqlCommand cmd = new SqlCommand("UPDATE [main] ([status]) VALUES (@status)", conn); conn.Open(); cmd.Parameters.AddWithValue("@status", "Rejected"); int i = cmd.ExecuteNonQuery(); conn.Dispose(); }}
Hi,Its probably simple but.. How do I update a column by just '1'..for example - heres my code: protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "HiddenConnection"; con.Open(); SqlCommand command = new SqlCommand(); command.Connection = con; Label productIDLabel = (Label)DataList1.FindControl("productIDLabel"); command.CommandText = "UPDATE Items SET numberclickedin = numberclickedin + 1 WHERE productID=@productID"; command.Parameters.Add("@productID", productIDLabel.Text); command.ExecuteNonQuery(); con.Close(); command.Dispose(); } As you can see in the bold text, I want to add 1 to the numberclickedin column.. and in my primative way Ive just typed +1What should I use instead?Thanks in advance,Jon
How can I create an update statement that will allow me to fill in a column if the previous column already has data in it? I am trying to do and UPDATE/SET command that allows me to extract information and populate columns within a table. However, the UPDATE/SET has to make sure that it is not overwriting information that is already in the column and if there is, to populate the column next to it, and so on until all the columns are populated.
In my UPDATE/SET I am pulling data from another table to populate into the 'add_diag' columns however, I'm not sure how to write in SQL the ability to monitor all the columns, and if for example the first three are full to then populate into the fourth and so on.
Here is my UPDATE/SET statement (while involved, I think I need something in my WHERE clause in order for this to be resolved):
Code:
update ad set add_diag_1=dsm_code from #add_diags ad join Doc_Entity de on ad.patient_id=de.patient_id and ad.episode_id=de.episode_id and doc_code = 'DCDIAG' join Patient_Assignment pa on de.patient_assignment_id = pa.patient_assignment_id and convert(char(8),de.effective_date,112) = convert(char(8),pa.date_discharged,112) left outer join Doc_Diag_Axis_I_III dx1 on de.doc_session_no=dx1.doc_session_no and de.current_version_no=dx1.version_no where dx1.sequence_no=2 and de.is_locked = 'Y' and dx1.rule_out = 'N' and is_billable = 'Y' and dx1.axis_type IN ('1','2') and de.status in ('CO' , 'SA')
Please excuse my ignorance. I've researched this and it appears I am asking to do something that is ridiculous, so please let me know what is wrong with my design (or my brain). I'd like to update an ID number in a table. It is an identity column. In my solution I'm adding a lot of new entries into my table and deleting old ones. Call me anal, but It's driving me nuts that my ID numbers are growing so large so quickly and that I have so many unused ID's. If you were to look over my data ID's they would be something like 1,3,45,78,88,89,103,140,219. What I'm trying to do is renumber my data so that my data currently at say ID# 1067 can be moved to the unused ID#2, etc. So I either need a way to update an Identity column...or I need a way find the lowest unused number among a list of ID's. So is there anyway to achieve what I am trying to do? I see this guy had my same OCD issue (without a solution) :-(
how can i update a column with datatype of text with a combination of columns having a datatype of float? do i convert the float columns to varchar/char/?? and/or can i convert the column i am updating?
hi i want to update column with new value in a table is it possible to do so in stored procedure . the name of the column will be an input to stored procedure ie at the time of writing the stored procedure i dont know which column the user will be updating
Does anyone know of the SQL statement to add additional comuns to an existing table. I know i can do it through enterprise managaer, but I want to see if I can do it from query analyzer or some script to add columns without having to recreate the table. Or a way to save off the data and recreate the table then placing data back in? I hope that makes sense. I am thinking of this from the sens of doing all updates through source safe
If amc.amc2>0 then “UPDATE amc set AMC2= AMC2 + “ & val(txtamt.text) & “where am1=1” else if amc.amc2<0 then “UPDATE amc set AMC2= “ & val(txtamt.text) & “where am1=1” end if
Here I check the value of column with if condition statement. I need to check the column with out if condition statement.
What is my doubt is that how I can check value of amc2 column while updating.
eg: update amc set case when amc2>0 then AMC2= AMC2 + “ & val(txtamt.text) like this
Is it possible with “case-when -end”?
If it is possible I can solve a big problem in my project. Can you give me an example with this query?
Hi, I need to update column week14 in table PastWeeks with data from Eng_Goal and then result of some calculation from table AverageEngTime in the row Goal and Used respectively. I used the following and was not successful. Please advice. Thank you.
Hey...newbie question: I've got three columns in my database, thethird of which is blank right now, and I need it to equal the value ofcolumn one minus column two. While I can accomplish this in the .aspxpage with a subroutine, I want to do it in SQL Server so I can simplyread the data in the page and not have to do any calculations. Helpplease? Thanks.Erik
I have a column the customer table which holds the telephone numbers,
0293 232 232 2
2323 23232333
0222229999 00
the problem is that they all appear with spaces in different places, i need to remove all the spaces, remove the leading 0 if ther eis one and put +44 on the front.
Hi all, I'm trying to update various rows in my DB with a new value once an action occurs. I am using the following code which does not throw any exceptions, but also does not change the values. Can someone steer me in the right direction? public static void ChangeRefCode() { SqlConnection dbConn = new SqlConnection(ConnectDB.getConnectString()); SqlDataAdapter dataAdapt = new SqlDataAdapter("Select * from Posting",dbConn);
Hello I am trying to update a column within a table. I need to change all the (null) to yes. But I keep seeing Error: 0 record(s) affected. What is wrong with my syntax. My table name: Cat_B Column: Blog Current cell data: (null) Update to: yes This is the syntax I have tried: UPDATE Cat_B SET Blog = 'yes' Where Blog = '(null)'
My goal is to with one update statement, fill TABLE1.counter (currently empty) with the total count of TABLE2.e# (employee). Also, if TABLE1.e# isn't in TABLE2.e# then it sets it to "0" (TABLE1.e# 8 and 9 should have a counter of 0) This is for sqlplus.
e.g. TABLE2:
e# -- 1 2 3 4 5 5 6 7 7 1 2 3 4 5 UPDATE TABLE1 SET counter = ( SELECT COUNT(TABLE2.e#) FROM TABLE2 INNER JOIN TABLE1 ON (TABLE2.e# = TABLE1.e#) GROUP BY TABLE2.e#);
Is it possible to assign to a column a value passed as a parameter?
When I run the proc I get the following error :
Msg 245, Level 16, State 1, Procedure Transfer, Line 17
Conversion failed when converting the varchar value '@ID' to data type int.
----#################################################### USE [tbldata] GO /****** Object: StoredProcedure [dbo].[Transfer] Script Date: 05/19/2014 11:26:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Transfer](@ID int)
I have a excel file which has a column called "Code" and their values are A,B,C,D,E,F,G,H. I want to create a new column called "status" based on the values of "Code".
Code:
A B C D E F G H
If A,C,E,G then "status" = "Active" else if B,D,F,H then "Status" = "Inactive". I like to do it using "Derived Column".
Hi guys, I have a table with following columns and records. Empid Empname Phone Flag 14 Rajan 2143 116 Balan 4321 122 Nalini 3456 023 Ganesh 9543 0 Now i need to create a stored procedure which will convert the flag values to vice versa since it is a bit datatype. That is if execute the stored procedure it should convert all the flag values to 1 if it zero and zero's to 1. How? Pls provide me the full coding for the stored procedure. Thanx.
i am building a shopping cart. I want to update the UNIT_IN_STOCK column in database after order have been submitted. i want to subtract the quanity value from the order made from the UNIT_IN_STOCK column in database. how would the sql statement be like?? i tried this but it didnt work. any suggestions??
CREATE PROCEDURE update_Products_By_name (
@ProductName varchar, @UnitInStock int
) AS
UPDATE Products SET UnitInStock=(UnitInStock-@UnitInStock) WHERE ProductName = @ProductName GO
This problem is strictly an SQL problem, and I am about to lose my mind over it. I have a table named Inventory that has a column named PartialQty which is of type DECIMAL(11,4). I have shortened my query for simplicity, but here it is. DECLARE @pqty1 DECIMAL(11,4) SELECT @pqty1 = PartialQty FROM Inventory WHERE InventoryID = @invIDPRINT @pqty1 UPDATE Inventory SET PartialQty = 6.5513 WHERE InventoryID = @invID SELECT @pqty1 = PartialQty FROM Inventory WHERE InventoryID = @invIDPRINT @pqty1 Before this query is ran, the value in PartialQty is 1.2345. If I run this 2 times in a row, this is the output I get: RUN 1: 1.2345 (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) 6.0000
RUN 2: 6.0000 (1 row(s) affected) 6.5513
I don't understand 2 things. One is why the first run displays (1 row(s) affected) 4 times even though there is only one record with that InventoryID. And the other thing I don't understand is why the first time I run it, it loses all of the values after the decimal point. Please help, Scott
I am looking for suggestions on how to accomplish the following task with the least amount of hand keying that I can get away with.
I have a main table named Office and 4 other tables that have the Office table ID field value in them. I have been given a new set of ID values that need to replace the values that are currently in the Office table and then update the ID field in the other 4 tables.
I have only thought of 2 solution and I don’t like either one. 1 Add a new column to the Office table and key in the new ID’s then go through the pages that reference the old ID field and change the SQL queries to use the new field.
2 Change the value of the current Office ID field to the new value. Search the other 4 tables for the old value and then update them to the new value.
If your tables contain created and modified/updated dates what is the best practice for these?
1. Should you use UTC dates? 2. Do you use a default for the creation date (I assume yes)? 3. Should you create a trigger to handle the last update date? Or do you update the column directly in your stored procedures that modify data?
Also, as an aside if you store the user who created/updated the record do you store a foreign key reference to the user table or do you store the username as a varchar? Of course I know you'd normally store the fk, but I wasn't sure if the "logging" nature of the column suggests storing a string value.
I have the following stored procedure that inserts records and updates the new record. The parameter @rpt_id has a value of -1 when entering the procedure. It needs to be updated with the new record if (identity) once the record is inserted, bu sometimes the update does not happen. The new records ends up with -1 in the rpt_id column.
I have included the stored procedure. I will appreciate any ideas?
I'm looking for some performance assistance on updating a column value in a table that contains approximately 50 million rows. I have a permanent table in another database that has the key column and value to be set. My query is listed below, but I'm afraid it will run quite awhile. Any suggestions would be appreciated.
update mytable set column2 = b.column2 from mytable as a join mytable1 as b on a.column1 = b.column1
There is a one to one relationship between the two tables.
col1 col2 col3 col4 (No column name) A123 Test 1 Test 1 Y N 0 Y N 0 A125 Test 1 Test 9 Y N 0 N Y 0
but what I would like is col 1 populated As A123 until it hits A125 Â then populated A125 etc. Â I was thinking about using the iff but not getting anywhere fast.
One more question about this Custom Calendar table I'm creating. I have a column called "IsWorkdays" which indicates if the day represented by a row is a workday or not. For our purposes, I also need to create a row that accumulates those numbers by month. So, if it is the 3rd workday of the month, this column would have a 3. This is beyond my current T-SQL ability. Does anyone know how to do this?