Hi,
I am currently updating a column in my database table with the value typed into a text box. But it is updating with the new value, rather than taking away the value typed in from the present value of the column.
1. How would i subtract the value typed in away from the current column value?
2. I guess I need to check the column value is above 0 before updating, then rebind the control to show new values after the update has happened, incase two people are using it at once. How would this be achived?
Thanks for any help!!
Jon
P.S.
My code is:
private bool ExecuteUpdate(int quantity)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";
I'm in trouble. I have a table with some fields, one of them is an amount of money. One field indicates whether the amount is negetive or positive. This fields has only two possible values, 'N' and 'R'. 'N' means the amount is negative and 'R' means the amount is positive.
The problem I have is that I have to sum these amounts to give a total for each customer and report them as
customer1 total amount1 customer2 total amount2
I don't know how to make a query to bring these results. I know that sum would bring me the total amount for each customer but I don't know how to specify which fields are supposed to be negative so that it subtracts them instead of adding them.
By the way I'm not allowed to change the structure of the table.
hi all I want to find the set of rows that are present in result returned by first select statement & that are not there in the result of second select statement. Both select statement operate on tables having similar columns. Is there any way by which i can find such difference in results? Is this possible using EXCEPT function? plz help me.
I would like to know the best method or the simplest method to do the following. Take a datetime value and subtract a given number of hours. I am taking a UTC time and subtracting a given number or hours in a query. I seem to be getting mixed results.
One of the following selected fields is a sum. I need to subtract ISNULL(R.CMS_AMOUNT,0) where R.Waived = '1 from that amount. Pretty much just subtract those amounts where the waived field is 1. I am having trouble with the syntax. Can anyone help? Thanks.'
SELECT P.Efs_Network_ID , F.DBA_Name , F.ACCOUNT_STATUS , SUM(ISNULL(R.CMS_Amount,0)) - isnull(RA.Amount,0) AS Amount -- ?? isNULL(R.CMS_AMOUNT,0) WHERE R.Waived = '1' ??????
, isnull(SUM(RA.Pending),0) AS Pending , F.Salesman_no FROM tblPimsFDSLookup P INNER JOIN ACH_MerDemo F ON P.Efs_Network_ID = F.Efs_Network_ID LEFT OUTER JOIN tblrecovery R ON P.IntMid = R.IntMid LEFT OUTER JOIN( SELECT sum(isnull(Amount,0)) as amount , intmid , SUM(CASE WHEN RA.Status = 'P' THEN 1 ELSE 0 END) AS Pending FROM tblACHRecoveryAmounts RA --WHERE IntMid = 641046 WHERE RA.Status IN ('A','P','M','S') Group by intmid ) AS RA ON P.IntMid = RA.IntMid WHERE P.INTMID = @INTMID AND R.Waived = 0 AND Upgraded IS NULL GROUP BY P.Efs_Network_ID , F.DBA_Name , F.ACCOUNT_STATUS , RA.Amount ,F.Salesman_no
I need to write a SQL Query in which I have time1 and time2.
Now I need to find the difference between the time1 and time2 and if the difference is less then 15 minutes then I have to raise an Exception in SQL SERVER 2000.
If I have the total amount of 673000 that is passed as a parameter in my stored proc then, I need to do this:
Declare @TotalAmount money @TotalAmount = 673000 Col1 Col2 Col3 Test1 45 672955 --(I want to subtract 673000 from Col2 data) 673000-45 Test2 30 672925 --(I want to subtract 30 from the remaining amount of col3) Test3 100 672825 --(I want to subtract 100 from the remaining amount of col3)
How do I go about subtracting adjacent Rows? Let's say each day I entered one row entry into a table (tblFlowerHeight)showing the new height of a flower in one column(Height)...say if I had a second second column (ChangeFromLastHeight), how would I go about showing the difference between current height and the last recorded height?
I have a table for which I need a €œspecial€? running total. More specifically there should be a close communication between the credit and the debit column. The scenario should be in the following order
Credit
Debit
Balance credit
Balance debit
6
0
6
0
5
0
11
0
0
4
7
0
0
9
0
2
3
0
1
0
0
5
0
4
0
2
0
6 I have to point out that this is done in a grouped way where the CustormerID is the grouped clause. Now I have achieved this to a point where the calculations work only if the credit column is bigger than 0, but when the account starts with debit I get only sums of the column not the needed subtractions. What am I missing? Thanks in advance. DECLARE @PrevRunBal MONEY --Overall running total SET @PrevRunBal = 0 DECLARE @PrevGrpBal MONEY --Running total resets when account changes SET @PrevGrpBal = 0 DECLARE @PrevRunCnt INT --Overall running count (ordinal rank) SET @PrevRunCnt = 0 DECLARE @PrevGrpCnt INT --Running count resets when account changes SET @PrevGrpCnt = 0 DECLARE @PrevAcctID INT --The "anchor" and "account change detector" SET @PrevAcctID = 0 changes SET @PrevGrpBalP = 0 update Temp
SET --===== Running Total @PrevRunBal = RunBal = @PrevRunBal + Credit,
--===== Grouped Running Total (Reset when account changes) @PrevGrpBal = Bcredit = CASE
WHEN CustomerID = @PrevAcctID THEN CASE WHEN CREDIt > DEBIT or CREDIT = 0 THEN (@PrevGrpBal+CREDIT)-(DEBIT) WHEN DEBIT>CREDIT or DEBIT =0 THEN (@PrevGrpBal+DEBIT)-DEBIt END ELSE CASE WHEN CREDIT >DEBIT THEN (CREDIT) WHEN DEBIT > CREDIT THEN DEBIT -- restarts from 0 if only 1 rec. END
END,
--===== Running Count (Ordinal Rank) @PrevRunCnt = RunCnt = @PrevRunCnt + 1, --===== Grouped Running Total (Ordinal Rank, Reset when account changes) @PrevGrpCnt = GrpCnt = CASE WHEN CustomerID = @PrevAcctID THEN @PrevGrpCnt + 1 ELSE 1 -- Restarts count at "1" END,
--===== "Anchor" and provides for "account change detection" @PrevAcctID = CustomerID
I have a table CombinedSales script below (CreateCombSalesTable.sql) which contains the details of a sale.
A row in the table has two flags online/offline SalesAmount is the financial amount, online = 1 (online sales) online = 0 (combined sales off and online).
The table also contains the product and the client etc.,
What I am trying to do is subtract onlinesales from combinedsales within the query or outside I don't mind, to return the result as (below)
select skuid,SUM(SalesAmount),online,ClientName from t_CombinedSalesDetails where ClientName ='Asda' and SkuId = 200437 group by Skuid,Online,ClientName order by skuid
THIS is what I get below the online = 0 is the total sales of this product.
/****** Object: Table [dbo].[t_CombinedSalesDetails] Script Date: 27/08/2014 13:23:27 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON
I have a Column in my data that gives a financial period value in the YYYYMM format. i.e. an asset was re-valued in a particular period for example 201301. I need to find out the number(count) of periods(months) between another given period for example current period (201403) and the period provided in the table i.e. 201301.
I have a matrix which looks as follows: ----- Actuals | Budget ItemA 20 | 50 ItemB 45 | 30 ItemC 20 | 15
I would like to add a column with the difference between actuals and budget. Actuals/budget is 1 group in the matrix being the dimensionname. How can I calculate the difference (subtract actuals and budget), because if I just use the subtotal function it adds both totals together and I need to have the difference between them?
Hi all,I encountered this small problemI have two tables A and B with two columns 1 and 2 each, I would likethe first column of each table when match the first in the second tableis to subtract the second columnso the result would look as followsColumn 1 | Columnn 2where A1=B1 | A2-B2Now this is no problem so far ..But if there was no corresponding value in column 1 in either tables ..i.e. field A1 doesnt exist in Table B column 1, IT SHALL DO A2 - 0; or0-B2 ..NOW How can that be achieved ?Thanks all for your help
I have two date fields, start_date and end_date.I'd like to subtract the two dates, and come up with a number (thenumber of difference between the two dates).What function is there to do this? I haven't been able to find anythingin BOL.Start_date = 6/1/03End_date = 6/8/03End_date - start_date = 7*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
Hi there,I am trying to write a stored procedure in which I will retrieve SessionStartDate, SessionEndDate, and Duration (where Duration is calculdated by subtracting SessionEndDate from SessionStartDate).I was duration in the format of hours:minutes:seconds.The stored procedure is pasted below. I am getting the following error. Syntax error converting datetime from character string. Any ideas? ============================== CREATE PROCEDURE sp_ActiveSessions_UsersBrowsingDurationByDate_List ( @websiteID AS int = 0, @SelectedDateFrom AS dateTime, @SelectedDateTo AS dateTime) ASIF DateDiff(d,@SelectedDateTo,@SelectedDateFrom)=0begin set @SelectedDateFrom=null endIF ISNULL(@SelectedDateTo, '') = ''begin SET @SelectedDateTo = @SelectedDateFromendSET @SelectedDateTo = DATEADD(d, 1, @SelectedDateTo)SELECT UserID As 'User ID', SessionStartDate As 'Session Start Date', SessionEndDate AS 'Session End Date', ExitPageTitle As 'Exit Page Title', NumberOfPagesVisited As 'Number of Pages Visited', Convert(datetime, (CONVERT(DATETIME, SessionEndDate, 24) - CONVERT(DATETIME, SessionStartDate, 24)), 101) As 'Duration' FROM ActiveSessions WHERE UserID != 'Anonymous'GROUP BY SessionID, UserID, SessionStartDate, SessionEndDate, NumberOfPagesVisited, ExitPageTitleHAVING (min(SessionStartDate) BETWEEN @SelectedDateFrom AND @SelectedDateTo AND min(SessionEndDate) BETWEEN @SelectedDateFrom AND @SelectedDateTo)GO============================== <Columns> <asp:BoundColumn DataField="User ID" HeaderText="User ID"></asp:BoundColumn> <asp:BoundColumn DataField="Session Start Date" HeaderText="Session Start Date"></asp:BoundColumn> <asp:BoundColumn DataField="Session End Date" HeaderText="Session End Date"></asp:BoundColumn> <asp:BoundColumn DataField="Duration" HeaderText="Duration"></asp:BoundColumn> <asp:BoundColumn DataField="Number Of Pages Visited" HeaderText="Number Of Pages Visited"></asp:BoundColumn> <asp:BoundColumn DataField="Exit Page Title" HeaderText="Exit Page Title"></asp:BoundColumn> </Columns> ============================
Hello. How do I increment or decrement a date by adding/subtracting days? For example I want to add 4 days to the date today. I should get 07/31/2005 since today is 07/27/2005. And if I add 5 days then I should get 08/01/2005. Thank you.
I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.
I am trying to make a stored procedure in my website for updating an address:1 CREATE PROCEDURE dbo.UPDATE 2 ( 3 @add NVarchar(50), 4 @cit NVarchar(50), 5 @state NVarchar(50), 6 @zip NVarchar(50), 7 @CNum int 8 ) 9 10 UPDATE table_name 11 AppAdd = @add, AppCity = @cit, AppState = @state, AppZip = @zip 12 WHERE CertNum = @CNum When I try to save it it give me an error: Incorrect syntax near keyword 'UPDATE'Must declare scalar variable '@add'
Hi, I'm new to ASP.Net quite new to C# (My first attempt at a database website) and am trying to get a button to add "1" to "int" value called "Comments" a each time its pressed basically counting each time a comment is added. I also only wnat it to affect the row where "ModID" in my database is equal to the query string "ModID" I'm using on the page. I cannot find any tutorials so this is my best guess so far. This is probably a Noobie type stupid question but I'm stuck. This is the code I have so far for my Button_Click event: protected void Button_Click(object sender, EventArgs e){ SqlDataSource CommentCountDataSource = new SqlDataSource(); CommentCountDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["Main_Site_DatabaseConnectionString1"].ToString(); CommentCountDataSource.UpdateCommandType = SqlDataSourceCommandType.Text; CommentCountDataSource.SelectCommand = "SELECT (ModID, DateTimeLastComment, Comments) FROM Mods"; CommentCountDataSource.UpdateCommand = "UPDATE Mods SET (DateTimeLastComment=@DateTimeLastComment, Comments=@Comments) WHERE ModID=@ModID"; //How do i get the Where to use the query string info? CommentCountDataSource.UpdateParameters.Add("DateTimeLastComment", DateTime.Now.ToString()); CommentCountDataSource.UpdateParameters.Add("Comments", "10"); //"10" is just a value to test I'll change this to add "1" once I figure how. CommentCountDataSource.Update();} Sorry if I'm using the wrong lingo but as I say I'm new. If my code is a mile off then please can you send me in the right direction of some code that works.Thanks in advance if anyone can help me. Cheers,Alan
I am a DBA who is moving in the direction of minor database design. I have gone through the steps to get my tables normalized, and I am ready to get them set up so they will update from table to table. How do I set this up? I know SQL does not cascade like Access, so how is this done? From what I have read (Robert Vieira's book) I should use triggers? Any help would be appreciated. Dallas
strSQL = "UPDATE customers SET " strSQL &= "entryid = '" & strtheEntryid & " ' " strSQL &= "WHERE id =1 " right now in table id is my primary key field it increments by 1, I want to say get first record instead of saying id = 1, how to do that?
I have some code to hack in c#.. I have a database and when a form (C#) is loaded a copy of the table is made in a DataTable object. The form has a list box showing just the one column of info from the local DataTable. On the form it is possible to change a record, delete a record and add a record. These are all done in the local table.
The question, how do i send these changes back to the database. Currently it deletes the lot and copies all the local table values in. How do only do the affected row, UPDATE, INSERT etc
I have an ASP application that uses a stored procedure and ADO.net to update a sql server data file. The problem is I know the code is working, I don't have any errors with the ADO, no exceptions are caught. I can use the same basic code to insert a record using a different procedure. It is the update procedure that does not carry through.
So, I know I have a connection, the procedure works using the query builder directly so the procedure works, but when I run the code, I get no errors and no update to the datafile. I am not even sure how to trouble shoot this since I don't have an error to look up.
C# Code:-------------
private void UpdateIssue() { DateTime date = new DateTime(); date = Convert.ToDateTime(this.txtDate.Text);
//edit record in HelpDeskIssuesTbl here.
SqlConnection con = new SqlConnection("Data Source..."); SqlCommand comUpdateTicket = new SqlCommand("sp_UpdateHelpDeskIssues", con); comUpdateTicket.CommandType = CommandType.StoredProcedure; comUpdateTicket.Parameters.Add("@IssueID", this.GridView1.SelectedIndex.ToString()); comUpdateTicket.Parameters.Add("@EmpID", this.ddlEmployee.SelectedValue.ToString()); comUpdateTicket.Parameters.Add("@Date", date.ToShortDateString()); comUpdateTicket.Parameters.Add("@StatusID", this.ddlStatus.SelectedValue.ToString());
( @IssueID int, @EmpID int, @Date datetime, @StatusID int )
AS UPDATE HelpDeskIssuesTbl SET EmployeeID = @EmpID, IssueDate = @Date, IssueStatusID = @StatusID WHERE (IssueID = @IssueID) RETURN
Like I said the Stored Procedure does work when I run it directly in Visual Studio. I have double checked all the params and they all match up unless I am missing something.
My feeling with the SCD component is not that very solid. I have the feeling that the behavior of the insert/update strategy is not always correct an working. I will describe two problems that i encounter.
1. My destination table contains records with the value ''. Cause i don't want '' ( 2 single quotes) in our DWH i update the view that is the source with a case statement that changes the '' to NULL. But when i run the packages the '' values are not update with the NULL values. When i delete the destination table and run the package, the records are inserted with the NULL value as expected. Anyone who has experienced this problem?
2. When i create a new table and run the package so the destination table gets filled with records the SCD will insert alle records (for example 100). When i start the run directly after the first run, all records are updated instead of doing nothing what it should do cause all records exists.
I am looking for a way to update a sqldatasource what I have is a ASP Wizard applicationstep oneis a dataview with the select ability it displays an ID and Namein step two what i want it to do is take the ID from step ones select and put that into the where clause so I have select * from table where id = step1selectedID