Cannot Update Database Using Sql Statement... Help Please
Apr 19, 2008
Hi All,
I have watched one of the video tutorials under SQL Server section called "Connecting your web application to SQL server 2005 express edition" (number 8).
It was about creating a database with single table and then updating it by inserting new records in a text box an clicking on submit button. In code section there is a sql insert statement and connection string is via configurationManager (name of the connection string is taken from web.config and is spelled properly)
Anyway, my problem is that updating that database by filling the textbox and clicking submit button is not working.
I have no error message (nothing happens) - database is not updated.
If I add to the page a data grid view with updating and inserting selected then it all works. I was trying to use debbuging with break point setup but couldn't find any errors.I have done everything the same way as on the video.... I am beginner in C# so your help will be much appreciated.
Here is the code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
}protected void Submitbutton_Click(object sender, EventArgs e)
{
SqlDataSource dashDataSource = new SqlDataSource();dashDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["dashConnectionString1"].ToString();
dashDataSource.InsertCommandType = SqlDataSourceCommandType.Text;dashDataSource.InsertCommand = "INSERT INTO Email(EmailAddress, IPAddress, DateTimeStamp) VALUES (@EmailAddress, @IPAddress, @DateTimeStamp)";
dashDataSource.InsertParameters.Add("EmailAddress", EmailAddressTextBox.Text);dashDataSource.InsertParameters.Add("IPAddress", Request.UserHostAddress.ToString());
dashDataSource.InsertParameters.Add("DateTimeStamp", DateTime.Now.ToString());int rowsaffected = 0;
try
{
rowsaffected = dashDataSource.Insert();
}catch (Exception ex)
{Server.Transfer("Newsletter_problem.aspx");
}
finally
{dashDataSource = null;
}if (rowsaffected != 1)
{Server.Transfer("Newsletter_problem.aspx");
}
else
{Server.Transfer("Newsletter_confirm.aspx");
}
}
}
View 4 Replies
ADVERTISEMENT
Jul 23, 2005
Hello,I am trying to update records in my database from excel data using vbaeditor within excel.In order to launch a query, I use SQL langage in ADO as follwing:------------------------------------------------------------Dim adoConn As ADODB.ConnectionDim adoRs As ADODB.RecordsetDim sConn As StringDim sSql As StringDim sOutput As StringsConn = "DSN=MS Access Database;" & _"DBQ=MyDatabasePath;" & _"DefaultDir=MyPathDirectory;" & _"DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" &_"PWD=xxxxxx;UID=admin;"ID, A, B C.. are my table fieldssSql = "SELECT ID, `A`, B, `C being a date`, D, E, `F`, `H`, I, J,`K`, L" & _" FROM MyTblName" & _" WHERE (`A`='MyA')" & _" AND (`C`>{ts '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "'})"& _" ORDER BY `C` DESC"Set adoConn = New ADODB.ConnectionadoConn.Open sConnSet adoRs = New ADODB.RecordsetadoRs.Open Source:=sSql, _ActiveConnection:=adoConnadoRs.MoveFirstSheets("Sheet1").Range("a2").CopyFromRecordset adoRsSet adoRs = NothingSet adoConn = Nothing---------------------------------------------------------------Does Anyone know How I can use the UPDATE, DELETE INSERT SQL statementsin this environement? Copying SQL statements from access does not workas I would have to reference Access Object in my project which I do notwant if I can avoid. Ideally I would like to use only ADO system andSQL approach.Thank you very muchNono
View 1 Replies
View Related
Aug 29, 2006
I am currently having this problem with gridview and detailview. When I drag either onto the page and set my select statement to pick from one table and then update that data through the gridview (lets say), the update works perfectly. My problem is that the table I am pulling data from is mainly foreign keys. So in order to hide the number values of the foreign keys, I select the string value columns from the tables that contain the primary keys. I then use INNER JOIN in my SELECT so that I only get the data that pertains to the user I am looking to list and edit. I run the "test query" and everything I need shows up as I want it. I then go back to the gridview and change the fields which are foreign keys to templates. When I edit the templates I bind the field that contains the string value of the given foreign key to the template. This works great, because now the user will see string representation instead of the ID numbers that coinside with the string value. So I run my webpage and everything show up as I want it to, all the data is correct and I get no errors. I then click edit (as I have checked the "enable editing" box) and the gridview changes to edit mode. I make my changes and then select "update." When the page refreshes, and the gridview returns, the data is not updated and the original data is shown. I am sorry for so much typing, but I want to be as clear as possible with what I am doing. The only thing I can see being the issue is that when I setup my SELECT and FROM to contain fields from multiple tables, the UPDATE then does not work. When I remove all of my JOIN's and go back to foreign keys and one table the update works again. Below is what I have for my SQL statements:------------------------------------------------------------------------------------------------------------------------------------- SELECT:SELECT People.FirstName, People.LastName, People.FullName, People.PropertyID, People.InviteTypeID, People.RSVP, People.Wheelchair, Property.[House/Day Hab], InviteType.InviteTypeName FROM (InviteType INNER JOIN (Property INNER JOIN People ON Property.PropertyID = People.PropertyID) ON InviteType.InviteTypeID = People.InviteTypeID) WHERE (People.PersonID = ?)UPDATE:UPDATE [People] SET [FirstName] = ?, [LastName] = ?, [FullName] = ?, [PropertyID] = ?, [InviteTypeID] = ?, [RSVP] = ?, [Wheelchair] = ? WHERE [PersonID] = ? ---------------------------------------------------------------------------------------------------------------------------------------The only fields I want to update are in [People]. My WHERE is based on a control that I use to select a person from a drop down list. If I run the test query for the update while setting up my data source the query will update the record in the database. It is when I try to make the update from the gridview that the data is not changed. If anything is not clear please let me know and I will clarify as much as I can. This is my first project using ASP and working with databases so I am completely learning as I go. I took some database courses in college but I have never interacted with them with a web based front end. Any help will be greatly appreciated.Thank you in advance for any time, help, and/or advice you can give.Brian
View 5 Replies
View Related
Jan 9, 2015
Ok I have a query "SELECT ColumnNames FROM tbl1" let's say the values returned are "age,sex,race".
Now I want to be able to create an "update" statement like "UPATE tbl2 SET Col2 = age + sex + race" dynamically and execute this UPDATE statement. So, if the next select statement returns "age, sex, race, gender" then the script should create "UPDATE tbl2 SET Col2 = age + sex + race + gender" and execute it.
View 4 Replies
View Related
Aug 13, 2014
i was tasked to created an UPDATE statement for 6 tables , i would like to update 4 columns within the 6 tables , they all contains the same column names. the table gets its information from the source table, however the data that is transferd to the 6 tables are sometimes incorrect , i need to write a UPDATE statement that will automatically correct the data. the Update statement should also contact a where clause
the columns are [No] , [Salesperson Code], [Country Code] and [Country Name]
i was thinking of doing
Update [tablename]
SET [No] =
CASE
WHEN [No] ='AF01' THEN 'Country Code' = 'ZA7' AND 'Country Name' = 'South Africa'
ELSE 'Null'
END
What is the best way to script this
View 1 Replies
View Related
May 5, 2015
I am attempting to run update statements within a SELECT CASE statement.
Select case x.field
WHEN 'XXX' THEN
UPDATE TABLE1
SET TABLE1.FIELD2 = 1
ELSE
UPDATE TABLE2
SET TABLE2.FIELD1 = 2
END
FROM OuterTable x
I get incorrect syntax near the keyword 'update'.
View 7 Replies
View Related
Nov 9, 2007
It appears to update only the first qualifying row. The trace shows a row count of one when there are multiple qualifying rows in the table. This problem does not exist in JDBC 2000.
View 5 Replies
View Related
Jul 30, 2007
Hello,
I'm writing a fairly involved stored procedure. In this Stored Procedure, I have an update statement, followed by a select statement. The results of the select statement should be effected by the previous update statement, but its not. When the stored procedure is finish, the update statement seemed to have worked though, so it is working.
I suspect I need something, like a GO statement, but that doesnt seem to work for a stored procedure. Can anyone offer some assistance?
View 6 Replies
View Related
Dec 12, 2014
I run the following statement and it will not update beyond 7 million plus rows and I have about 38 million to complete. I keep checking updated row counts and after 1/2 day it's still the same so I know something is wrong because it was rolling through no problem when I initiated it. I need to complete ASAP so it's adding to my frustration. The 'Acct_Num_CH' field is an encrypted field (fyi).
SET rowcount 10000
UPDATE [dbo].[CC_Info_T]
SET [Acct_Num_CH] = 'ayIWt6C8sgimC6t61EJ9d8BB3+bfIZ8v'
WHERE [Acct_Num_CH] IS NOT NULL
WHILE @@ROWCOUNT > 0
BEGIN
SET rowcount 10000
UPDATE [dbo].[CC_Info_T]
SET [Acct_Num_CH] = 'ayIWt6C8sgimC6t61EJ9d8BB3+bfIZ8v'
WHERE [Acct_Num_CH] IS NOT NULL
END
SET rowcount 0
View 5 Replies
View Related
Jun 14, 2007
Hi,I have table with three columns as belowtable name:expNo(int) name(char) refno(int)I have data as belowNo name refno1 a2 b3 cI need to update the refno with no values I write a query as belowupdate exp set refno=(select no from exp)when i run the query i got error asSubquery returned more than 1 value. This is not permitted when thesubquery follows =, !=, <, <= , >, >= or when the subquery is used asan expression.I need to update one colum with other column value.What is the correct query for this ?Thanks,Mani
View 3 Replies
View Related
May 27, 2008
hi need help how to send an email from database mail on row update
from stored PROCEDURE multi update
but i need to send a personal email evry employee get an email on row update
like send one after one email
i use FUNCTION i get on this forum to use split from multi update
how to loop for evry update send an single eamil to evry employee ID send one email
i update like this
Code Snippet
:
DECLARE @id nvarchar(1000)
set @id= '16703, 16704, 16757, 16924, 17041, 17077, 17084, 17103, 17129, 17134, 17186, 17190, 17203, 17205, 17289, 17294, 17295, 17296, 17309, 17316, 17317, 17322, 17325, 17337, 17338, 17339, 17348, 17349, 17350, 17357, 17360, 17361, 17362, 17366, 17367, 17370, 17372, 17373, 17374, 17377, 17380, 17382, 17383, 17385, 17386, 17391, 17392, 17393, 17394, 17395, 17396, 17397, 17398, 17400, 17401, 17402, 17407, 17408, 17409, 17410, 17411, 17412, 17413, 17414, 17415, 17417, 17418, 17419, 17420, 17422, 17423, 17424, 17425, 17426, 17427, 17428, 17430, 17431, 17432, 17442, 17443, 17444, 17447, 17448, 17449, 17450, 17451'
UPDATE s SET fld5 = 2
FROM Snha s
JOIN dbo.udf_SplitList(@id, ',') split
ON split.value = s.na
WHERE fld5 = 3
now
how to send an EMAIL for evry ROW update but "personal email" to the employee
Code Snippet
DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)
SET @xml =CAST(( SELECT
FirstName AS 'td','',
LastName AS 'td','' ,
SET @body = @body + @xml +'</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@recipients =''
@copy_recipients='www@iec.com',
@body = @body,
@body_format ='HTML',
@subject ='test',
@profile_name ='bob'
END
ELSE
print 'no email today'
TNX
View 2 Replies
View Related
Aug 22, 2007
Dim lblock As Boolean chkChecked = lblock strSQL = "UPDATE CLIENTS SET " If blnCompleted = True Then strSQL = strSQL & "COMPLETED_DT = '" & Format(Now(), "MM/dd/yyyy") & "', " Else strSQL = strSQL & "LAST_SAVED_DT = '" & Format(Now(), "MM/dd/yyyy") & "', " End If strSQL = strSQL & "COMMENTS = '" & FixString(txtcomments.Text) & "' " _ & "WHERE client_ID = " & iclientID & ""I want to put my booleen value lblock to sql too, I probably need value of it, It is checkbox, called chkblock, . how would I include this to update statement database field for that BLOCK =
View 1 Replies
View Related
Sep 7, 2007
Hi, i nid help on update statement. I using 03 and a microsoft sql server 2000 database.
I use a more simple example of my error. A Northwind Database is use to update the Region table(RegionDescription)
User will 1st go in WebForm2.aspx and enter a id, if found will retrieve the data to WebForm1.aspx. User type "1" and retrieve Eastern to TextBox1.
User can choose to update the table by typing in a diff word into TextBox1. But when i type any word(e.g East) the page is refresh back to Webform1.aspx with the not updated data and the database is also not updated. Any idea?
WebForm2.aspx.vb Imports System.Data.SqlClient Public Class WebForm2
Inherits System.Web.UI.PageWeb Form Designer Generated Code Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page hereEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("id") = TextBox1.Text
Response.Redirect("WebForm1.aspx")End Sub
End Class
WebForm1.aspx.vb Imports System.Data.SqlClient Public Class WebForm1
Inherits System.Web.UI.Page
Web Form Designer Generated CodeDim cnn As New SqlConnection("Data Source=(local); Initial Catalog=Northwind;User ID=******; Password=******") Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Label1.Text = Session("id")
retrieveTitle()End SubSub retrieveTitle()
cnn.Open()Dim cmd As New SqlCommand
cmd.CommandText = "SELECT * FROM Region WHERE RegionID = '" + Session("id") + "'"
cmd.Connection = cnnDim dr As SqlDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
TextBox1.Text = dr("RegionDescription").ToString
End If
cnn.Close()End SubSub UpdateTitle(ByVal title As String)
cnn.Open()Dim sqlstr As String = "UPDATE Region SET RegionDescription = '" + title + "' WHERE RegionID = '" + Session("id") + "'"
Trace.Write(sqlstr)Dim cmd As New SqlCommand(sqlstr, cnn)
cmd.ExecuteNonQuery()
cnn.Close()End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UpdateTitle(TextBox1.Text)End Sub
End Class
View 4 Replies
View Related
Mar 13, 2008
I have a SQL Table with the following columns
ID, Date, Meeting, Venue, Notes
What Update statement do i need to update a simple grid view in Visual Studio?I have been experementing but when i click update it updates the whole column insted of the one i was trying to update.
Please can you help? Thanks
View 1 Replies
View Related
Jun 4, 2008
I need some help. please. Here is what I got. From the webpage I can pull the following data to update a table. update Vehicle set Name='TestUnitName' ,Make='TestMake', Model='TestModel', SoftwareVersion='TestVersion', DynamicChange='1', ProviderID='1', Description='TestDescription', VIN='TestVIN', IMEI='TestSIM', EngineTypeId=' ', Phone=' ', MobilePhoneProviderID='' where VehicleID=64 But I also get the error: "The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Vehicle_EngineTypes". The conflict occurred in database "Telemetry", table "dbo.EngineTypes", column 'EngineTypeId'.The statement has been terminated." How do I solve this issue? Actually what I am trying to do is, when EngineTypeId=' ' , I want to set is to NULL and same for the MobilePhoneProviderID. Any help would be appreciated. Thanks in advance.
View 14 Replies
View Related
May 17, 2004
Hey all,
I need to set a column value where the id is within a string. However, I need to set the column to a default value if the id is not within the string. Hope that was easy to understand!
ie:
This currently works...
SET @strSQL = 'UPDATE tblTest SET Archive = 1 WHERE RecID IN (' + @IDList + ')
If the ID is not in the list then I want that column set to 0. How can I do this?
Thanks in advance,
Pete
View 5 Replies
View Related
Sep 2, 2004
Hi
I use a update sub, the problem is that i got an error, the error is:
Syntax error in UPDATE statement.
I guess the UPDATE statement is:
strUpdate = "Update tblUsers Set UserName=@UserName, Password=@Password, RetypePassword=@RetypePassword, Email=@Email, Comments=@Comments Where UserID=@UserID"
Remark:I use Acceess DataBase, exactly the same code works fine in SQL, i just changed the DataBase(From Access to SQL).
Is the problem can be in other place?
Thank you very much for your assistance.
View 3 Replies
View Related
Oct 14, 2004
Hi, I'm having trouble writing this update statement and was wondering if anyone could help me out :
My database is sort of set up lilke this:
There are 3 tables: Orders, OrderDetails and Inventory
Orders has a pk called OrderID.
OD has several ProductIDs listed for that OrderID
Inventory has 2 fields, the pk InventoryID(which is the same as
ProductID) and QOH
So OD kinda looks like this:
OrderID ProductID Quantity Cost
192 12 2 $10
192 3 1 $12
192 14 2 $50
193 12 1 $11
.... .
...
...
so what i want to do is take each productID for a specific orderid
and decrement the inventory for it by OD.quantity
This is what I was trying
UPDATE Inventory
Set QOH = QOH - @qty
WHERE Inventory.InventoryID IN (
SELECT ProductID
FROM OrderDetails
WHERE OrderDetails.OrderID = @OrderID
and @qty = OrderDetails.Quantity
)
but, i'm having no luck...... any suggestions ?
View 2 Replies
View Related
Dec 15, 2004
what would the syntax be for the following update statement?
"UPDATE [Stocklist]
SET
[client] to textbox2.text
[notes] to textbox3.text
[paid] to textbox4.text
[status] to "old"
WHERE
[Make] = dropdownlist1.SelectedValue
[Model] = dropdownlist2.SelectedValue
[IMEI] = dropdownlist3.SelectedValue
[status] = new"
I know this is a simple question even for someone who is just starting out , thats why I posted it into the "Getting Started" forum.
Thanx in Advance
View 2 Replies
View Related
Feb 15, 2001
Hi,
I am a SQL Novice - I have a table called 'users' in which I need to modify the user's email id e.g., from seanu@hotmail.com to seanu@yahoo.com and I have over 150 rows where I should be changing 'domain' name only..
Any help with an Update Statement is highly appreciated..
Thanks,
-Srini.
View 2 Replies
View Related
Oct 27, 2000
I have a table that looks like this.
tkinit adir adate1
0007 0.00 01/01/1996
0007 0.00 01/01/1997
0007 25.00 01/01/1998
0007 27.00 06/01/1998
0008 0.00 01/01/1996
0008 0.00 01/01/1997
0008 32.00 01/01/1998
0008 37.00 06/01/1998
I need to populate the adir field where the adate < 12/31/1998 with the rate where adate = 01/01/1998.
I cant seem to figure out exactly how the statement should go so that I populate each timekeepers rate with their specific rate.
Thanks
Jason Fitch
View 2 Replies
View Related
Sep 27, 1999
Is there any way to create a "dynamic" update statement in a stored procedure?
Lets say I want to choose whether to update all columns in a table or just one. If I want to update just one column, is there a way to make the other columns keeping their values instead of NULL?
Thanks!
Pete
View 1 Replies
View Related
Aug 29, 2003
I am looking for a solution to my unique problem.
myTable is having following records
ID Field1 Field2 Field3 Field4
1 x y 100 0
2 xx zz 5 0
3 x y 200 1
4 a b 1 1
5 a b 2 0
6 k L 78 1
7 aa bb 25 1
8 k L 15 0
Now the problem is if I want to update a latest record's(if you go by ID)Field4 with 2 for the records where Field1 + Filed2 is unique, can I do this in a single query?
I can select the unique record by the following query
select Field1,Field2 from myTable group by Field1,Field2 having count(ID)>1
Any ideas?
View 4 Replies
View Related
Mar 3, 2008
Hi first post, so apologies if this is in wrong forum.
I am needing to update a field in one table, where a particular value of another table is TRUE, and update that table based on a common field in both tables.
at the moment my query is:
IF EXISTS (SELECT * FROM _tblSnapShotAUSProfServicesOrderLines_Daily
WHERE _tblSnapShotAUSProfServicesOrderLines_Daily.Produc tRelProductName like 'Prof%')
UPDATE OrderHeader_details
SET ServicesSold = 'Y'
WHERE OrderHeader_details.OrderRef = _tblSnapShotAUSProfServicesOrderLines_Daily.OrderR ef
In its current format, I get the column prefix is incorrect which makes sense sort of.
No matter which way I change this, I cannot get the query to work. I one form, it works but essentially performs two seperate statements, one with the select, and one with the update which unfortunately updates every row in the table.
Any assistance is appreciated.
Mick
View 1 Replies
View Related
Sep 24, 2007
Hello,
I need help with a sql update statement i need it to convert a datetime value to a specific format. For some reason it statement will only update the row only when i convert the datetime value to a varchar, i ran it in mssql sql server management studio and it works, the database is a mssql 2000 i think. If i try to compare the datetime value and they are both DateTime values it fails, if i convert them to varchar and run them they succeed, what i also noticed is when when are date values are that the value i passed in the query is that they are in a different format, i guess the database stores them as mon/dd/yyyy hh:mm:ss. but when i run the query that failed i get this as the results of the values from variables @Date1 & @Date2: They are the same and they failed. So if anyone knows any thing any help is surely appreciated this really sucks.
Failed
Date 1: Sep 23 2007 9:54PM
Date 2: Sep 23 2007 9:54PM
---------------------------------------------
Need help with making this work in C#:
Code:
string sql = string.Format(
"UPDATE [Contact Sheet] SET CallAttempt1 = {0}, CallAttempt2 = {1}, "
+ "CallAttempt3 = {2}, Status = '{3}' WHERE ContactID = {4} AND ModifiedDate = 'CONVERT(VARCHAR(50), {5}, 0)'", ..............................);
This statement ran in MSSQl Studio Management and works:
Code:
DECLARE @Date1 AS VARCHAR(50)
DECLARE @Date2 AS VARCHAR(50)
SET @Date2 = CONVERT(DATETIME, '9/23/2007 9:54:40 PM', 0);
SET @Date1 =
(SELECT Convert(VARCHAR(50), ModifiedDate, 0) FROM [Contact Sheet] WHERE CustomerID = 22);
IF @DATE1 = @DATE2
BEGIN
PRINT 'Success'
END
ELSE
BEGIN
PRINT 'Failed'
-- PRINT @TmpDate
PRINT 'Date 1: ' + @DATE1
PRINT 'Date 2: ' + @Date2
END
This one fails everytime:
Code:
DECLARE @Date1 AS DATETIME
DECLARE @Date2 AS DATETIME
SET @Date2 = CONVERT(DATETIME, '9/23/2007 9:54:40 PM', 0);
SET @Date1 =
(SELECT Convert(DATETIME, ModifiedDate, 0) FROM [Contact Sheet] WHERE CustomerID = 22);
IF @DATE1 = @DATE2
BEGIN
PRINT 'Success'
END
ELSE
BEGIN
PRINT 'Failed'
-- PRINT @TmpDate
PRINT 'Date 1: ' + CONVERT(VARCHAR(50), @DATE1, 0)
PRINT 'Date 2: ' + CONVERT(VARCHAR(50), @Date2, 0)
END
View 1 Replies
View Related
May 19, 2005
can I do something like this in update statement
update test
set Code=
Case When Action='D' then 'Failed'end,
from test1
View 2 Replies
View Related
Feb 28, 2006
Hey everyone, first time poster, and this problem has been bugging me all morning.
I am attempting to UPDATE a temp table (#Patient_Bill) with amounts derived from another table using a stored procedure that is used by a Powerbuilder Data Window.
Here is my statement:
UPDATE #Patient_Bill
SET balance_amount =
(select sum(balance_amount) from Payment py WHERE #Patient_Bill.patient_id = b.patient_id)
WHERE #Patient_Bill.patient_id = Payment.Patient_id
My goal is whenever the Powerbuilder data window is called that their "balance_amount" is shown on the data window (only one line since it's specific to patient).
However, whenever this is called I get the following error:
Insert Error: Column name or number of supplied values does not match table definition
Is my SQL code above pulling too many lines? I want only one line to populate in my data window based off the specific Patient_id.
Thanks, and I hope my explanation made sense!
View 6 Replies
View Related
Feb 8, 2008
Hello,
I am trying to update three fields in a tbl (c) from the sum of another tbl (b).
But also tbl (b) also needs to be joined to tbl (a) to meet a criteia.
I also do not want lengthy statement. Could someone tell me what I am doing wrong with my statement below?
UPDATE DBO.HIST3
SET INTRA_WGT = SUM(DBO.HIST2.EXT_TUBE_WGT),
INTRA_MKT = SUM(DBO.HIST2.EXT_MKT_AMT),
INTRA_NET = SUM(DBO.HIST2.GROSS_AMOUNT)
WHERE DBO.HIST3.SHIP_PLANT,DBO.HIST3.BILL_DATE IN
(SELECT DBO.HIST2.SHIP_PLANT,DBO.HIST2.BILL_DATE
FROM DBO.HIST2
INNER JOIN DBO.HIST1 ON
DBO.HIST2.INVOICE_NBR = DBO.HIST1.INVOICE_NBR
WHERE INVOICE_TYPE = 'IP'
GROUP BY DBO.HIST2.BILL_DATE ,DBO.HIST2.SHIP_PLANT)
The table (Hist3) and (Hist2) needs to be joined by two fields to get correct results, but I get the following error msgs.
Msg: An aggregate may not appear in the set list of an UPDATE statement.
Any advise?:S
View 2 Replies
View Related
Feb 12, 2004
hi,
I want to do some thing like:
Update @table1 set col1=(select col1 from table2 where
table2.col2=@table1.col2)
where @table1.col2=table2.col2
here @table1 is a table variable.
I can not get thro this update.Please help.
regards,
harsh
View 1 Replies
View Related
Feb 26, 2004
Hi
I want to add an IF clause in the update statement
update account set
a1 = '45',
(Make a2 = '123' when a3=11 else make a2='222'),
where a4='10'
How do I do that?
Thanks
View 2 Replies
View Related
Apr 28, 2008
Hi all,
I have a table called "dimcustomer" which has 25 columns in it out of which account name is one of them. There is another table called "dw_Organisation" which comes from a different source which also has the account name in it. There are about 15K rows in the "Dimcustomer" table where the account names are nulls. I want to use the account names in the "dw_Organisation" table to update the account names in the "Dimcustomer" table. The join info and SQL i'm using is as given below...
UPDATE dimcustomer
SET account = (SELECT b.name
FROM dimcustomer a, tibcostg..dw_organisation b
where a.GUID = b.commonid and a.account is null)
WHERE EXISTS
(SELECT b.name
FROM dimcustomer a, tibcostg..dw_organisation b
where a.GUID = b.commonid and a.account is null)
The above SQL throws me the following error...
quote:Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
It would be really helpful if you could advice me on where things are going wrong on the above SQL...Many thanks for your help.
View 3 Replies
View Related
May 17, 2008
Hi,
I am a little confued with the below SQL. Based on the where clause of the update statement I was expecting the @products table to be updated with the maximum version of the label (i.e., version 2) but that isn't the case. Could anybody please explain?
Many Thanks,
declare @products table(
productuid int,
labeluid int
)
insert into @products values (46047,-1)
insert into @products values (46047,-1)
declare @labels table(
productuid int,
labeluid int,
ctype varchar(10),
version int
)
insert into @labels values (46047,123,'landscape',1)
insert into @labels values (46047,345,'portrait',2)
update ct
set ct.labeluid = cv.labeluid
from @products ct
join @labels cv on ct.productuid = cv.productuid
where cv.version = (
select max(version) from @labels cv2
where cv.productuid = cv2.productuid
and cv.ctype = cv2.ctype
)
select * from @products
View 6 Replies
View Related
Dec 2, 2005
Hi, everyone. I was wondering if you can assist me with an update statement. I'm not a pro in SQL, and use it every once in awhile.
Let me explain the situation. In the "insured.insured_name1", we have a good number of names in the "insured_name1" column that begin with a "~ " and then a name. For example, it would read as
"~ Hamburger House" I'd say there are about 500 names like these. What we want to do is remove the tilda symbol and space from all of these names so that it would read as "Hamburger House" instead. I'm sure there's a statement that can update all of these names, but would appreciate your help.
View 4 Replies
View Related